Friday, June 15, 2012

Shorten a URL using api

Shorten a URL using is an URL shortener service, and it allow us to shorten url using their API. And we can connect to their API using PHP Curl:
$login='your username';
$appkey='your app key';
$api_url = '
format=xml&login='.$login.'&apiKey='.$appkey; //call the API
 $curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, $api_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 $response = curl_ex_ec($curl); curl_close($curl);
 //parse the XML response and return the url
$xml_object = new SimpleXMLElement($response);
echo $xml_object->results->nodeKeyVal->shortUrl; //output the shortened url

No comments :

Post a Comment