PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php class ShortURL { const ALPHABET = '23456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ-_'; const BASE = 51; // strlen(self::ALPHABET) public static function encode($num) { $str = ''; while ($num > 0) { $str = self::ALPHABET[($num % self::BASE)] . $str; $num = (int) ($num / self::BASE); } return $str; } public static function decode($str) { $num = 0; $len = strlen($str); for ($i = 0; $i < $len; $i++) { $num = $num * self::BASE + strpos(self::ALPHABET, $str[$i]); } return $num; } } echo ShortURL::encode('https://sqlize.online/sql/mysql57/c3fda9cc7efeab41b99645c2ddaad743/');
Show:  
Copy Clear