Home >Backend Development >PHP Tutorial >Example code for php to generate short URL

Example code for php to generate short URL

小云云
小云云Original
2018-03-09 13:22:112084browse

This article mainly shares with you the example code for generating short URLs in PHP. I hope you can learn how to use PHP to generate short URLs.

function SuoUrl($url=''){
    $urlcode =$this->shorturl($url);
}function shorturl($url){
    $url=crc32($url);    $result=sprintf("%u",$url);    $res = $this->code62($result);    return $res;
}function 
code62($result){
    $show='';    while($x>0){        $s=$x % 62;        if ($s>35){            $s=chr($s+61);
        }elseif($s>9&&$s<=35){            $s=chr($s+55);
        }        $show.=$s;        $x=floor($x/62);
    }    return $show;
}

Related recommendations:

How to use php to implement short URL jump

php method to implement long URL and short URL

php super simple code for short URL

The above is the detailed content of Example code for php to generate short URL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn