Skip to the content...

Welcome to the David Walsh Blog. I'm a MooTools, Dojo, jQuery, CSS, and PHP Web Developer located in Madison, Wisconsin, United States. Please contact me if I can make your experience on my website better.

Create an Is.Gd URL Using PHP

5 Responses »

Is.Gd is a URL-shortening service much like TinyURL. Using PHP's cURL library, you can create shortened URLs on the fly with ease.

The PHP

//gets the data from a URL  
function get_isgd_url($url)  
{  
	//get content
	$ch = curl_init();  
	$timeout = 5;  
	curl_setopt($ch,CURLOPT_URL,'http://is.gd/api.php?longurl='.$url);  
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);  
	$content = curl_exec($ch);  
	curl_close($ch);
	
	//return the data
	return $content;  
}

//uage
$new_url = get_isgd_url('http://davidwalsh.name/php-imdb-information-grabber');

"is.gd" is much shorter than "tinyurl.com" so if you need the URL to be as short as possible, use this method.

Discussion

  1. chris
    December 29, 2008 @ 9:30 am

    They do supply an API, you know: http://is.gd/api_info.php

  2. December 29, 2008 @ 11:57 am

    Ah, I’m glad you did this.

    is.gd is my URL ‘shortener’ of choice. :)

    I’m looking forward to the re-design too BTW!

  3. December 29, 2008 @ 12:40 pm

    ‘Is.gd’ has an API! :-)

    This URL will return just the shortened URL: (no confirmation message)

    http://is.gd/api.php?longurl=http://www.example.com

  4. December 29, 2008 @ 1:46 pm

    Thanks for the tip guys. I’ve adjusted my article accordingly.

  5. hanoi
    January 5, 2009 @ 11:39 pm

    Hi, How do you highlight PHP syntax in the example above?

    Could you show me a list of WordPress plugins you are using on this blog?

    Thanhks

    :)

Be Heard!

Share your thoughts with fellow developers of all skill levels! I want to hear from you!

Name*:
Email*:
Website:  
Wrap your code with <code> tags, f00!