The bit.ly API allows developers to interact in a programmatic way with the bit.ly website. The current API version is 2.0.1.
It’s a very simple way to shorten the URL through bit.ly API.

	/**
     * Function: URL_shortener
     *
     * @description : Create a shorten URl from a long URL
     * @param  $ : $url
     * @return : none
     * @author : sumon.
     * @last -modified-by: sumon.
     */

	function URL_shortener($url ="")
	{
		$api_data = file_get_contents("http://api.bit.ly/shorten?version=2.0.1&longUrl=".$url."&login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07");
		$array_data = json_decode($api_data);
		$result = $array_data->results;
		
		foreach($result as $results)
		{
			$short_url = $results->shortUrl;
		}
		return $short_url;
	}
	
	

It’s too simple to call that API. 🙂

Advertisements