This article mainly introduces the PHP short URL and the conversion between the number of methods, involving PHP operation string skills, with a certain reference value, the need for friends can refer to the
-->
This article gives an example of how PHP short URLs and numbers are converted to each other. Share to everyone for your reference. The implementation methods are as follows:
?
| 1, 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?php/** * Convert number to short URL code * * @param int $number number * @return string short URL code/function Generate_code ($number) {$out = ""; $codes = "ABCDEFGHJKMNPQRSTUVWXYZ23456789ABCDEFGHJKMNPQRSTUVWXYZ"; while ($number >) {$key = $number%, $number = Floor ($number/54)-1; $out = $codes {$key}. $out} return $code s{$number}. $out; /** * Convert short URL code to digital * * @param string $code short URL code * @return int Digital/function Get_num ($code) {$codes = "Abcdefghjkmnpqrstu VWXYZ23456789ABCDEFGHJKMNPQRSTUVWXYZ "; $num = 0; $i = strlen ($code); for ($j =0; $j <strlen ($code); $j + +) {$i-; $char = $code {$j}; $pos = Strpos ($codes, $char); $num = (POW ($i) * ($pos + 1 )); } $num--; return $num; } |
I hope this article will help you with your PHP program design.