Home Backend Development PHP Tutorial 怎样用PHP把电话号码和姓名加星号?解决思路

怎样用PHP把电话号码和姓名加星号?解决思路

Jun 13, 2016 am 10:12 AM
phone quot replace TEL

怎样用PHP把电话号码和姓名加星号?
在网上找了一下,一个教材不行的

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);

我想把姓名和电话(固话8位或者手机11 中间部分变成*号

------解决方案--------------------

PHP code
$tel1 = "13888111188";$tel2 = "+8613888111188";$tel3 = "0861088111188";$tel4 = "086-010-88111188";echo preg_replace('/(^.*)\d{4}(\d{4})$/','\\1****\\2',$tel1),"\n";echo preg_replace('/(^.*)\d{4}(\d{4})$/','\\1****\\2',$tel2),"\n";echo preg_replace('/(^.*)\d{4}(\d{4})$/','\\1****\\2',$tel3),"\n";echo preg_replace('/(^.*)\d{4}(\d{4})$/','\\1****\\2',$tel4),"\n";<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
PHP code
//屏蔽电话号码中间的四位数字function hidtel($phone){    $IsWhat = preg_match('/(0[0-9]{2,3}[\-]?[2-9][0-9]{6,7}[\-]?[0-9]?)/i',$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);    }}<div class="clear">
                 
              
              
        
            </div>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between cell phone and mobile phone? What is the difference between cell phone and mobile phone? Jan 04, 2021 pm 03:34 PM

Differences: 1. Different meanings of communication. Cell phone refers to a digital cellular mobile phone, and mobile phone refers to a mobile phone. 2. Explain the difference in meaning. Cell phone means mobile phone, and mobile phone means mobile phone. 3. The user groups are different. Cell phone is American English and is widely used in Canada and the United States; mobile phone is British English and is widely used in Europe.

Leak reveals Redmi Note 14 Pro camera and display details Leak reveals Redmi Note 14 Pro camera and display details Jun 26, 2024 am 06:52 AM

Successors of the Redmi Note 13 series phones are expected to land in about three months. While Xiaomi hasn't said anything about the new lineup, the first few details of the Redmi Note 14 Pro have leaked. This leak comes from Digital Chat Station, a

Vivo Y300 Pro packs 6,500 mAh battery in a slim 7.69 mm body Vivo Y300 Pro packs 6,500 mAh battery in a slim 7.69 mm body Sep 07, 2024 am 06:39 AM

The Vivo Y300 Pro just got fully revealed, and it's one of the slimmest mid-range Android phones with a large battery. To be exact, the smartphone is only 7.69 mm thick but features a 6,500 mAh battery. This is the same capacity as the recently launc

HMD releases HMD 105 and HMD 110 feature phones with long battery life but lacking Nokia branding HMD releases HMD 105 and HMD 110 feature phones with long battery life but lacking Nokia branding Jun 14, 2024 am 11:24 AM

HMDhasreleasedvariousdevicesoflate,includingseveralNokia-brandedfeaturephones.Forcontext,barelyamonthhasgonebysincethecompanypresentedtheNokia32102024,areincarnationoftheNokia3210tomarkits25thanniversary.Additionally

How to use the REPLACE function to replace a specified part of a string in MySQL How to use the REPLACE function to replace a specified part of a string in MySQL Jul 25, 2023 pm 01:18 PM

MySQL is a commonly used relational database management system that provides a variety of functions to process and operate data. Among them, the REPLACE function is used to replace the specified part of the string. In this article, we will introduce how to use the REPLACE function for string replacement in MySQL and demonstrate its usage through code examples. First, let’s take a look at the syntax of the REPLACE function: REPLACE(str,search_str,replace_str).

Sources say Samsung Electronics is testing TEL's Acrevia GCB equipment to improve EUV lithography processes Sources say Samsung Electronics is testing TEL's Acrevia GCB equipment to improve EUV lithography processes Sep 03, 2024 pm 09:49 PM

According to news from this site on September 3, Korean media TheElec reported yesterday that Samsung is testing Tokyo Electron (TEL)'s AcreviaGCB gas cluster beam (Note from this site: GasClusterBeam) system. TEL's AcreviaGCB system was released on July 8 this year. It can locally and accurately shape EUV lithography patterns through gas cluster beams, thereby repairing pattern defects and reducing pattern roughness. Industry insiders believe that TEL's Acrevia system can play a similar role to Applied Materials' CenturaSculpta system, that is, directly shape EUV exposure patterns, reduce costly EUV multiple exposures, thereby shortening the photolithography process and improving the overall

What are the string search and replace techniques in Python? What are the string search and replace techniques in Python? Oct 20, 2023 am 11:42 AM

What are the string search and replace techniques in Python? (Specific code example) In Python, strings are a common data type, and we often encounter string search and replace operations in daily programming. This article will introduce some common string search and replacement techniques, accompanied by specific code examples. To find a specific substring in a string, you can use the find() method or index() method of the string. The find() method returns the index of the first occurrence of the substring in the string.

OnePlus reveals some core specs of Ace 3 Pro ahead of June 27 launch OnePlus reveals some core specs of Ace 3 Pro ahead of June 27 launch Jun 24, 2024 pm 10:05 PM

OnePlus is gearing up to launch the Ace 3 Pro in China. The launch is set for June 27, and the company has just confirmed a couple of core specs of the upcoming Android flagship. As previously speculated, the phone will feature the Snapdragon 8 Gen 3

See all articles