亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php生成短域名函數(shù)

 更新時(shí)間:2015年03月23日 17:30:34   投稿:hebedich  
短網(wǎng)址流行的已經(jīng)有一段時(shí)間了,以前做新浪微博應(yīng)用的時(shí)候就有接觸,但沒有搞清楚,最近再次接觸到這個(gè)東東,仔細(xì)研究了下,發(fā)現(xiàn)短網(wǎng)址其實(shí)也挺容易的。下面就將使用php生成短網(wǎng)址的實(shí)現(xiàn)方法做一下記錄。

php生成短域名函數(shù)

public function createRandCode($string) {
    $code = '';
    $hex_code = '1qaz2wsx3edc4rfv5t-gb6yhn7ujm8ik9ol0p_';
    $now = microtime(true) * 10000;
    $strlen = strlen($hex_code);
 
    $hash_code = hash('sha256', $string);
 
    // 這里會(huì)為編碼定義一個(gè)隨機(jī)的長(zhǎng)度,長(zhǎng)度取決于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;
  }

以上所述就是本文給大家分享的代碼的全部?jī)?nèi)容了,希望大家能夠喜歡。

相關(guān)文章

最新評(píng)論