当前位置:Gxlcms > PHP教程 > PHP序列号生成函数和字符串替换函数代码_PHP教程

PHP序列号生成函数和字符串替换函数代码_PHP教程

时间:2021-07-01 10:21:17 帮助过:10人阅读

代码如下:

/**
* 序列号生成器
*/
function snMaker($pre = '') {
$date = date('Ymd');
$rand = rand(1000000,9999999);
$time = mb_substr(time(), 5, 5, 'utf-8');
$serialNumber = $pre.$date.$time.$rand;
// echo strlen($serialNumber).'
';
return $serialNumber;
}
echo snMaker();
/**
* 将一个字符串的一部分替换成某一特定字符
* @param str or int $str 需要处理的字符串
* @param str or int $to 将替换成什么字符串
* @param int $start 保留前几个字符
* @param int $end 保留后几个字符
*/
function hideString($str = 'hello', $to = '*', $start = 1, $end = 0) {
$lenth = strlen($str) - $start - $end;
$lenth = ($lenth < 0) ? 0 : $lenth;
$to = str_repeat($to, $lenth);
$str = substr_replace($str, $to, $start, $lenth);
return $str;
}
echo hideString();

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/325597.htmlTechArticle 代码如下:

/** * 序列号生成器 */ function snMaker($pre = '') { $date = date('Ymd'); $rand = rand(1000000,9999999); $time = mb_substr(time(), 5, 5, 'utf-8'); $...

人气教程排行