: This article mainly introduces a function for generating short URLs in PHP. For more information about PHP tutorials, see. The short website is no stranger to everyone, especially for Weibo applications. In fact, it is very easy to implement this function.
0) {$ s = $ result % 62; if ($ s> 35) {$ s = chr ($ s + 61 );} elseif ($ s> 9 & $ s <= 35) {$ s = chr ($ s + 55);} $ sUrl. = $ s; $ result = floor ($ result/62);} return $ sUrl;} $ url = 'www .qttc.net '; $ sUrl = urlShort ($ url); echo'
'; Echo' url: '. $ url .'
'; Echo' short URL: '. $ sUrl;?>
The above result is output:
Website: www.qttc.net
Short URL: SwOOy3
You can store short URLs in the database for a ing relationship. You can use nginx rewrite rules to generate, restore, and redirect short URLs.
The above introduces a PHP short URL generation function, including the content, hope to be helpful to friends interested in PHP tutorials.