Home >Backend Development >PHP Tutorial >Example code for php to generate short URL
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!