短域名php,php生成短域名函数_PHP教程
生活随笔
收集整理的這篇文章主要介紹了
短域名php,php生成短域名函数_PHP教程
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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;
}
總結(jié)
以上是生活随笔為你收集整理的短域名php,php生成短域名函数_PHP教程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信小程序php get_php处理微信
- 下一篇: php 怎么执行unoconv,web执