<form method="post" action="">
    <input type="text" value="<?php
    
if ( isset($_POST["url"]) ) {
        echo 
$_POST['url'];
    } else {
        echo 
'http://';
    }
    
?>" name="url" size="60" />
    <input type="submit" value="Shorten URL" />
</form>
<br />
<?php
if ( isset($_POST['url']) && strlen($_POST['url']) <= 250 ) {
    
// force the url to have http:// in front.
    
$prettyUrl str_replace('http://'''$_POST['url']);
    
$prettyUrl stripslashes(strip_tags('http://'.$prettyUrl));

    include(
'bitly.php');

    
$bitly = new bitly('username''apikey');

    
$bitly->setFormat('xml');

    
$shortUrl $bitly->shorten($prettyUrl);

    if ( 
$shortUrl ) {
        echo 
'<p>The shortened URL is : <a href="'.$shortUrl.'" title="Shortened URL" target="_blank">'.$shortUrl.'</a>.</p>
        <p>Copy it from here: <form method="get" action=""><input type="text" value="'
.$shortUrl.'" /></form></p>';
    } else {
        echo 
'<p>URL conversion failed.</p>';
    }
}