How do I use PHP to add an asterisk to my phone number and name? Solution Ideas

Source: Internet
Author: User
How do I use PHP to add an asterisk to my phone number and name?
On the internet to find a bit, a textbook is not good

http://www.haogongju.net/art/848588

Preg_replace ('/(0[0-9]{2,3}[\-]?[ 2-9]) [0-9]{3,4} ([0-9]{3}[\-]?[ 0-9]?) /I ', ' $1****$2 ', $phone);

I'd like to have my name and phone number (landline 8 or phone 11, the middle part becomes *

------Solution--------------------
PHP code
 $tel 1 = "13888111188"; $tel 2 = "+8613888111188"; $tel 3 = "0861088111188"; $tel 4 = "086-010-88111188"; Echo preg_replace ('/(^.*) \d{4} (\d{4}) $/', ' \\1****\\2 ', $tel 1), "\ n"; Echo Preg_replace ('/(^.*) \d{4} (\d{4}) $/', ' \\1****\\2 ', $tel 2), ' \ n '; echo preg_replace ('/(^.*) \d{4} (\d{4}) $/', ' \\1****\ \2 ', $tel 3), "\ n", Echo preg_replace ('/(^.*) \d{4} (\d{4}) $/', ' \\1****\\2 ', $tel 4), "\ n"; 
------Solution--------------------
PHP code
//mask phone number in the middle Four-bit numeric function Hidtel ($phone) {$IsWhat = Preg_match ('/(0[0-9]{2,3}[\-]?[ 2-9][0-9]{6,7}[\-]? [0-9]?) /I ', $phone); Fixed phone if ($IsWhat = = 1) {return preg_replace ('/(0[0-9]{2,3}[\-]?[ 2-9]) [0-9]{3,4} ([0-9]{3}[\-]?[ 0-9]?)    /I ', ' $1****$2 ', $phone);    } else {return preg_replace ('/(1[358]{1}[0-9]) [0-9]{4} ([0-9]{4})/I ', ' $1****$2 ', $phone); }} 
  • 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.