Get the App
SLTechnology News&Howtos  ›  Development  › 

How php hides intermediate characters

Shulou Source: shulou.com Published: 2022-06-03 16:17:27 10月03日 Update

This article introduces how php hides the middle characters. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Php hide the middle characters: 1, through the "function func_substr_replace () {...}" method to hide the middle part of the number; 2, through the "function substr_cut ($user_name) {...}" method to hide the middle and replace with an asterisk.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How does php hide intermediate characters?

PHP implements partial character hiding

/ * * hide partial string * # this method is mostly used to hide the middle digits of mobile phone number or ID number and bank card number * / function func_substr_replace ($str, $replacement ='*', $start = 1, $length = 3) {$len = mb_strlen ($str,'utf-8'); if ($len > intval ($start+$length)) {$str1 = mb_substr ($str,0,$start,'utf-8') $str2 = mb_substr ($str,intval ($start+$length), NULL,'utf-8');} else {$str1 = mb_substr ($str,0,1,'utf-8'); $str2 = mb_substr ($str,$len-1,1,'utf-8'); $length = $len- 2;} $new_str = $str1; for ($I = 0; $I < $length; $iTunes +) {$new_str. = $replacement } $new_str. = $str2; return $new_str;} / * retains only the beginning and end characters of the string, and hides the formatted name * / function substr_cut ($user_name) {$strlen = mb_strlen ($user_name, 'utf-8') of * @ param string $user_name name * @ return string instead of * in the middle of the two characters. $firstStr = ucfirst (strtolower (mb_substr ($user_name, 0,3, 'utf-8')); $lastStr = strtolower (substr ($user_name,-3)); if ($strlen = = 2) {$hideStr = str_repeat (' *, strlen ($user_name, 'utf-8')-1); $result = $firstStr. $hideStr;} else {$hideStr = substr (str_repeat ("*", $strlen-6), 0,3); $result = $firstStr. $hideStr. $lastStr;} return $result;} about how to hide intermediate characters in php is shared here. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.

Tags: Character part method content name string number more help yes two interest card number number boy buddy mobile phone mobile number article asterisk Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology Linux Docker Apple