PHP phone number in the middle to replace the asterisk instance

Source: Internet
Author: User


Regular Expression method

1, the string contains more than one mobile phone number

The code is as follows Copy Code

<?php
$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 cell phone number in the string

The code is as follows Copy Code

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

Do not implement the regular expression
1, use Substr_replace string partial substitution function

The code is as follows Copy Code

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

2. Use string intercept function substr

  code is as follows copy code

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

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.