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;
}
以上所述就是本文给大家分享的代码的全部内容了,希望大家能够喜欢。
PHP 独特的语法混合了 C、Java、Perl 以及 PHP 自创新的语法。它可以比 CGI或者Perl更快速的执行动态网页。用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML文档中去执行,执行效率比完全生成HTML标记的CGI要高许多。下面介绍了十个PHP高级应用技巧。 1, 使用 ip2long() 和 long2ip() 函数来把 IP 地址转化成整型存储到数据库里
454
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号