u.nu, the shortest urls: the API

Here’s a simple code snippet copied from the home page of u.nu.

<?php
$original_url = ‘http://www.google.com/’;
$request = ‘http://u.nu/unu-api-simple?url=’ . urlencode($original_url);
$response = file_get_contents($request);
if (substr($request, 0, 4) == ‘http’)
{
echo “Shortened URL = $response”;
}
else
{
list ($error_code, $error_message) = explode(‘|’, $response);
echo “Error = $error_message ($error_code)”;
}
?>

PS: u.nu is a great url shortener service since it generates very short and easy-to-remember urls.

Tags: , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">