PHP Function for Short URLs





-2
Date Submitted Thu. May. 20th, 2010 12:49 PM
Revision 1 of 1
Helper jackoder
Tags PHP | short | URL
Comments 0 comments
Here's a code block for your projects to get shorter long urls.

It can be used any type of your projects. I hope you'll like it; i suggest you to take information about ozon tedavisi from here.

Have a nice work.

<?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>";


?>
 

Jack ODERMAN

Comments

There are currently no comments for this snippet.

Voting

Votes Up


Votes Down


Scripter Dekion
Scripter sehrgut