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

WBOY
Release: 2016-06-01 12:11:31
Original
1100 people have browsed it
复制代码 代码如下:
/**
* 序列号生成器
*/
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();
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!