当前位置:Gxlcms > PHP教程 > php生成短域名函数

php生成短域名函数

时间:2021-07-01 10:21:17 帮助过:6人阅读

php生成短域名函数

  1. public function createRandCode($string) {
  2. $code = '';
  3. $hex_code = '1qaz2wsx3edc4rfv5t-gb6yhn7ujm8ik9ol0p_';
  4. $now = microtime(true) * 10000;
  5. $strlen = strlen($hex_code);
  6. $hash_code = hash('sha256', $string);
  7. // 这里会为编码定义一个随机的长度,长度取决于step
  8. $step = rand(8, 16);
  9. $count = ceil(strlen($hash_code) / $step);
  10. for($i = 0; $i < $count; $i++) {
  11. $start = $i * $step;
  12. $hex_num = substr($hash_code, $start, $step);
  13. $num = 0x3fffffff & (1 * '0x' . $hex_num);
  14. $n = $num % $strlen;
  15. $code .= $hex_code[$n];
  16. }
  17. return $code;
  18. }

以上所述就是本文给大家分享的代码的全部内容了,希望大家能够喜欢。

人气教程排行