Papermashup

Subscribe


Tweets


"RT @bethgordon: .@Tesco Please rethink archaic 'Approved by Mums'. Pretty sure it's not just mothers who make childcare decisions. https://…"

@ashleyford 2 days ago

"Is there ever a time that @DFS doesn't have a sale on?"

@ashleyford 6 days ago

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

PHP CURL & Tiny URL

AshleyAshley

Here’s how to use PHP CURL and the TinyURL api to generate tiny urls on the fly. This is a similar tutorial to the one I wrote a while back on using the Twitter API

I’ve set the variable $maketiny as the url that you want to shorten. This then gets passed into the function and processed with CURL. CURLOPT_RETURNTRANSFER returns the value of curl_exec($ch); as a string and doesn’t just display it on the screen allowing us to process the data further.


//the url you want to make tiny
$maketiny = 'http://www.papermashup.com';

function make_tiny($url)  
{  
	$ch = curl_init();  
	$timeout = 5;  
	curl_setopt($ch, CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);  
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);  	
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);  
	$data = curl_exec($ch);  
	curl_close($ch);  
	return $data;  
}
$tinyurl = make_tiny(''.$maketiny.'');

php echo $tinyurl; ?>

demodownload

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Comments 9