欢迎访问WDPHP素材源码!今天是2024年03月29日 星期五,下午好!别打盹哦!
您好,游客 [ 马上登录 | 注册帐号 | 微信登录 | QQ登录]
当前位置:首页 > 教程 > PHP教程 > 

php生成短域名函数
栏目分类:PHP教程    发布日期:2017-08-01    浏览次数:4181次     收藏

php生成短域名函数

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

相关热词: 短域名函数

源码 模板 特效 素材 资源 教程 站长