Get the App
SLTechnology News&Howtos  ›  Development  › 

How to hide several digits in php

Shulou Source: shulou.com Published: 2022-06-02 12:02:19 10月01日 Update

This article will explain in detail how to hide a few digits in php. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Php to achieve hidden number of several methods: 1, to create a PHP sample file; 2, through the "function hidtel ($phone) {...}" method to hide the phone number and mobile phone number between 4 digits.

This article operating environment: Windows7 system, PHP7.1, Dell G3 computer.

PHP hides the middle 4 digits of phone number / mobile number

/ * 1, hide the middle 4 digits of the phone number and mailbox * / function hidtel ($phone) {/ / hide mailbox if (strpos ($phone,'@')) {$email_array = explode ("@", $phone); $prevfix = (strlen ($email_array [0]))

< 4) ? "" : substr($phone, 0, 3); //邮箱前缀 $count = 0; $str = preg_replace('/([\d\w+_-]{0,100})@/', '***@', $phone, -1, $count); $rs = $prevfix . $str; return $rs; } else { //隐藏联系方式中间4位 $Istelephone = preg_match('/(0[0-9]{2,3}[\-]?[2-9][0-9]{6,7}[\-]?[0-9]?)/i', $phone); //固定电话 if ($Istelephone) { 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[0-9]{1}[0-9])[0-9]{4}([0-9]{4})/i', '$1****$2', $phone); } } } /** * 2、使用hidtel */ public function useHidel() { $phone1 = $this->

Hidtel ("010-57033050"); $phone2 = $this- > hidtel ("01057033050"); $mobil = $this- > hidtel ("13661226666"); $email = $this- > hidtel ("1963632356@qq.com"); return $phone1.''.$phone2.''.$mobil.''.$email;}

Effect:

/ / the rule determines whether it is verified when the mailbox, mobile phone number and user account log in.

$checkmail ='/\ w+ ([- +.]\ w+) * @\ w+ ([-.]\ w+) *\.\ w+ ([-.]\ w+) * /'; / / whether the mailbox if (preg_match ($checkmail,$userName)) {$type = 'email'; $value = $userName } elseif (preg_match ("/ ^ 1 [34578]\ d {9} $/", $userName)) {/ / whether the mobile number $type = 'mobile'; $value = $userName;} else {$type =' user_name'; $value = $userName } this is the end of the article on "how to hide several numbers in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Number mobile phone mailbox phone number article mobile number mobile number method more good practical content effect document article regular environment user computer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Huawei OPPO Reno NVidia