PHP serial number generation function and string replacement function code

Source: Internet
Author: User
I'm glad to have two functions that are useful to you. The first one is used to generate the serial number. The second one is used to encrypt some strings. modify it a little bit, you can find the effect of some hidden characters such as itb ********* @ gmail.com that we often see when retrieving the password. The code is as follows:
/**
* Serial number generator
*/
Function snMaker ($ pre = ''){
$ Date = date ('ymmd ');
$ Rand = rand );
$ Time = mb_substr (time (), 5, 5, 'utf-8 ');
$ SerialNumber = $ pre. $ date. $ time. $ rand;
// Echo strlen ($ serialNumber ).'
';
Return $ serialNumber;
}
Echo snMaker ();
/**
* Replace a part of a string with a specific character.
* @ Param str or int $ str string to be processed
* @ Param str or int $ to replace the string
* @ Param int $ start keep the first few characters
* @ Param int $ end keep the last few 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 ();
Related Article

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.