Return to Snippet

Revision: 27035
at May 20, 2010 12:26 by jackoder


Initial Code
<?php
function shorturl($url){
    $length = strlen($url);
    if($length > 45){
        $length = $length - 30;
        $first = substr($url, 0, -$length);
        $last = substr($url, -15);
        $new = $first."[ ... ]".$last;
        return $new;
    }else{
        return $url;
    }
}
?>

// USAGE

<?php

$longurl= "http://www.google.com/search?q=symfony+project&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:tr:official&client=firefox-a";
$shorturl = shorturl($longurl);
echo "<a href=\"$longurl\">$shorturl</a>";


?>

Initial URL

                                

Initial Description
Dear php coders, 

Here's a code block that you can use in your projects to get shorter long urls. 

Also recommend these articles about [ozon tedavisi](http://www.denizliozon.com) here. 

Have a nice coding.

Initial Title
Short URL Function with PHP

Initial Tags
url, php

Initial Language
PHP