首頁 > php教程 > PHP源码 > 主體

生成短域名使用的

PHP中文网
發布: 2016-05-26 08:19:16
原創
1245 人瀏覽過

跳至

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 * &#39;0x&#39; . $hex_num);
            $n = $num % $strlen;
            $code .= $hex_code[$n];
        }

        return $code;
    }
登入後複製

                   

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!