Replace the phone number with the "*" or hide the last IP address.

Source: Internet
Author: User
$ String = "13826589549 ";
$ Pattern = "/(\ D {3}) \ D (\ D {2 })/";
$ Replacement = "\ $1 ***** \ $3 ";

Print preg_replace ($ pattern, $ replacement, $ string );

Output result: 138 **** 9549

The matching result is what I want, but the matching mode is incorrect. It can only match 7 digits, and the remaining 4 digits cannot match, and \ $3 does not exist at all.

Which of the following statements is true?

$ String = "13826589549 ";
$ Pattern = "/(\ D {3}) \ D {4} (\ D {4 })/";
$ Replacement = "\ $1 ***** \ $2 ";

Print preg_replace ($ pattern, $ replacement, $ string );

You can also use the string truncation method to hide numbers in the middle.
Function suohao ($ phone ){
$ P = substr ($ phone,). "*****". substr ($ phone );
Return $ P;
}
Echo suohao ($ string );
Output: 138 **** 9549

 
The last number of hidden IP addresses is *
<? PHP echo preg_replace ("/[^ \.] {1, 3} $/", "*", $ IP);?>

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.