/ Published in: PHP
URL: http://davidwalsh.name/create-tiny-url-php
TinyURL is an awesome service. For those who don’t know what TinyURL is, TinyURL allows you to take a long URL like “http://davidwalsh.name/jquery-link-nudging” and turn it into “http://tinyurl.com/67c4se”. Using the PHP and TinyURL API, you can create these tiny URLs on the fly!
Simply provide the URL and you’ll received the new, tiny URL in return. If you use Twitter, you’ll have noticed that Twitter automates tiny URL creation for URLs in tweets.
Expand |
Embed | Plain Text
//gets the data from a URL function get_tiny_url($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } //test it out! $new_url = get_tiny_url('http://davidwalsh.name/php-imdb-information-grabber'); //returns http://tinyurl.com/65gqpp echo $new_url
You need to login to post a comment.
