Code Examples for Short URL API
If you want to use the API of your Short URL script, you can start with our code examples.
Replace http://melt.li/ with the Domain or URL of your own Short URL script.
<?php
$longUrl = 'http://www.example.com/test/123/';
$shortUrl = file_get_contents('http://melt.li/?api=1&u=' . urlencode($longUrl));
echo $shortUrl;
?>
If the code above doesn't work, try this:
<?php
$longUrl = 'http://www.example.com/test/123/';
$ch = curl_init('http://melt.li/?api=1&u=' . urlencode($longUrl));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$shortUrl = @curl_exec($ch);
curl_close($ch);
echo $shortUrl;
?>