a few words about web development

PHP: Nice URL shortener to use from PHP

Another straight to the point solution
In this post I would like to present you a nice URL shortening service that you may use from PHP in a very simple way (perhaps simplest possible!).
Let's say you want to shorten url like this:
http://www.my-website-is-here.com/index.php?subpage
To do this you need this simple code:
$url = 'http://www.my-website-is-here.com/index.php?subpage';
$new_url = file_get_contents('http://is.gd/api.php?longurl=' . urlencode($url));
Now you can echo $new_url to see a new address (which is this case is: http://is .gd/jRqN9).
Pretty amazing, huh?

Is.Gd announced that they will soon stop using is.gd domain. So the way to shorten addresses will be:
[xode]
$url = 'http://www.my-website-is-here.com/index.php?subpage';
$new_url = file_get_contents('http://v.gd/create.php?format=simple&url=' . urlencode($url));
[/code]
Not a big difference, is it? And the resulting address is: http://v. gd/7hCRcu, so it's exactly same length.
As you can notice there is format parameter in the URL above. You can put there "json" or "xml" instead of "simple", but then you will need to decode the output (using json_decode() or simplexml_load_string() ).

Comments