php生成短域名函数

yipeiwu_com6年前PHP代码库

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;
  }

以上所述就是本文给大家分享的代码的全部内容了,希望大家能够喜欢。

相关文章

thinkphp多表查询两表有重复相同字段的完美解决方法

框架:thinkphp 版本:3.2.3 内容:查询语句 解决问题:重复字段问题 $Data = M('a')->where($where) ->Fiel...

php小经验:解析preg_match与preg_match_all 函数

正则表达式在 PHP 中的应用在 PHP 应用中,正则表达式主要用于:•正则匹配:根据正则表达式匹配相应的内容•正则替换:根据正则表达式匹配内容并替换•...

PHP 读取文件内容代码(txt,js等)

<?php /* 作者:bjf; 应用:读取文件内容; */ function read_file_content($FileName) { //open file $fp=fop...

PHP缓存机制Output Control详解

在php5.2版本的配置中,默认output_buffering为关闭状态,因此运行下面三行代码将会出现一个警告: Warning: Cannot modify header infor...

PHP中new static()与new self()的区别异同分析

本文实例讲述了PHP中new static()与new self()的区别异同,相信对于大家学习PHP程序设计能够带来一定的帮助。 问题的起因是本地搭建一个站。发现用PHP 5.2 搭建...