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

Example code for php to generate short URL

小云云
Release: 2023-03-21 06:10:01
Original
2087 people have browsed it

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;
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template