PHP Serial number generation function and string substitution function code _php tips

Source: Internet
Author: User
Tags rand strlen
Copy Code code as follows:

/**
* Serial Number generator
*/
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). ' <br/> ';
return $serialNumber;
}
Echo Snmaker ();
/**
* Replace part of a string with a specific character
* @param str or int $str strings to be processed
* @param what string the str or int $to will be replaced
* @param int $start Preserve the first few characters
* @param int $end reserved after several characters
*/
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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.