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 to Create a RetroPie on Raspberry Pi – Graphical Guide

    Today we get to play amazing games on our super powered game consoles, PCs, VR headsets, and even mobile devices.  While I enjoy playing new games these days, I do long for the retro gaming systems I had when I was a kid: the original Nintendo...

  • By
    Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

Incredible Demos

  • By
    Table Cell and Position Absolute

    If you follow me on Twitter, you saw me rage about trying to make position: absolute work within a TD element or display: table-cell element.  Chrome?  Check.  Internet Explorer?  Check.  Firefox?  Ugh, FML.  I tinkered in the console...and cussed.  I did some researched...and I...

  • By
    HTML5 Placeholder Styling with CSS

    Last week I showed you how you could style selected text with CSS. I've searched for more interesting CSS style properties and found another: INPUT placeholder styling. Let me show you how to style placeholder text within INPUTelements with some unique CSS code. The CSS Firefox...

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!