PHP mobile phone number in the middle of replacing asterisks example _php tutorial

Source: Internet
Author: User
Today, small part of the students to introduce the use of preg_replace function to the middle of a number of mobile phone numbers to replace the Chengshing number, this in many sites will have to do so, let me introduce the example method.


Regular Expression methods

1, the string contains more than one mobile phone number

The code is as follows Copy Code

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

2, only one mobile phone number in the string

The code is as follows Copy Code

$haoma = "15012345678";
echo Preg_replace ("/(D{3}) d{5}/", "$1*****", $haoma);
150*****678
?>

Do not implement regular expressions
1. Replace the function with the Substr_replace string part

The code is as follows Copy Code

$string 1 = "13264309555";
Echo Substr_replace ($string 1, ' * * * * *, 3,5);
132*****555
?>

2. Using the string intercept function substr

The code is as follows Copy Code

Echo substr ($string 1,0,3). " ". substr ($string 1,8,3);
132*****555
?>

http://www.bkjia.com/PHPjc/632653.html www.bkjia.com true http://www.bkjia.com/PHPjc/632653.html techarticle Today, small part of the students to introduce the use of preg_replace function to the middle of a number of mobile phone numbers to replace the Chengshing number, this in many sites will have to do, the following I would like to introduce the instance of the party ...

  • 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.