新聞中心
這篇文章主要介紹“php如何生成短域名函數(shù)”,在日常操作中,相信很多人在php如何生成短域名函數(shù)問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”php如何生成短域名函數(shù)”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
php生成短域名函數(shù)
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; }
到此,關(guān)于“php如何生成短域名函數(shù)”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
網(wǎng)站題目:php如何生成短域名函數(shù)-創(chuàng)新互聯(lián)
本文路徑:http://fisionsoft.com.cn/article/pches.html