Example of replacing asterisks with digits in the middle of the php mobile phone number

Source: Internet
Author: User
Regular expression method 1. the string contains multiple mobile phone numbers. the code is as follows: & lt ;? Php $ s & amp; 39; manager Wang: 13999312365 manager Li: 13588958741 & amp; 39; $ spreg_replace (& amp; 39;

Regular expression method

1. the string contains multiple mobile phone numbers. the code is as follows:

  1. $ S = 'manager Wang: 13999312365 manager Li: 13588958741 ';
  2. $ S = preg_replace ('# (d {3}) d {5} (d {3 })#', '$ {1} ***** $ {2}', $ s );
  3. Echo $ s;
  4. // Manager Wang: 139 ***** 365 manager Li: 135 ***** 741
  5. ?>

2. the string contains only one mobile phone number. the code is as follows:

  1. $ Haoma = "15012345678 ";
  2. Echo preg_replace ("/(d {3}) d {5}/", "$1 *****", $ haoma );
  3. // 150 ***** 678
  4. ?>

Implementation without regular expressions

1. use the substr_replace string to replace the function. the code is as follows:

  1. USD string1 = "13264309555 ";
  2. Echo substr_replace ($ string1 );
  3. // 132 ***** 555
  4. ?>

2. use the string truncation function substr. the code is as follows:

  1. Echo substr ($ string1,). "*****". substr ($ string1 );
  2. // 132 ***** 555
  3. ?>

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.