Create an Is.Gd URL Using PHP

By  on  

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('https://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.

Recent Features

  • By
    How I Stopped WordPress Comment Spam

    I love almost every part of being a tech blogger:  learning, preaching, bantering, researching.  The one part about blogging that I absolutely loathe:  dealing with SPAM comments.  For the past two years, my blog has registered 8,000+ SPAM comments per day.  PER DAY.  Bloating my database...

  • By
    Conquering Impostor Syndrome

    Two years ago I documented my struggles with Imposter Syndrome and the response was immense.  I received messages of support and commiseration from new web developers, veteran engineers, and even persons of all experience levels in other professions.  I've even caught myself reading the post...

Incredible Demos

  • By
    MooTools TextOverlap Plugin

    Developers everywhere seem to be looking for different ways to make use of JavaScript libraries. Some creations are extremely practical, others aren't. This one may be more on the "aren't" side but used correctly, my TextOverlap plugin could add another interesting design element...

  • By
    Chris Coyier’s Favorite CodePen Demos IV

    Did you know you can triple-heart things on CodePen? We’ve had that little not-so-hidden feature forever. You can click that little heart button on any Pen (or Project, Collection, or Post) on CodePen to show the creator a little love, but you can click it again...

Discussion

  1. Chris

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

  2. 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. ‘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. Thanks for the tip guys. I’ve adjusted my article accordingly.

  5. hanoi

    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

    :)

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!