Home  >  Article  >  php教程  >  PHP序列号生成函数和字符串替换函数代码

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

WBOY
WBOYOriginal
2016-06-13 11:59:501472browse

复制代码 代码如下:


/**
* 序列号生成器
*/
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 $to = str_repeat($to, $lenth);
$str = substr_replace($str, $to, $start, $lenth);
return $str;
}
echo hideString();

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn