A character in a string specified in PHP is replaced with an asterisk we have a function that can be implemented such as Substr,preg_replace,substr_replace and so on, I give these three functions respectively to introduce an example, mainly talk about telephone, ID card.
Replace the phone number string with the asterisk code:
The code is as follows |
Copy Code |
$str = "15832818835"; Echo substr ($str, 0, 3). ' '. substr ($str, 8,strlen ($STR));//reserved for the first three and last three bits ?> or with regular $s = ' manager Wang of www.bKjia.c0m: 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 ?> |
Replace string middle position character obscured stars number
The code is as follows |
Copy Code |
function Half_replace ($STR) { $len = strlen ($STR)/2; Return Substr_replace ($str, Str_repeat (' * ', $len), Ceil (($len)/2), $len); }
echo half_replace (' Test '), "n", Half_replace (' tests '), "n", Half_replace (' exceptions '); |
The PHP ID number is marked with an asterisk
The code is as follows |
Copy Code |
echo strlen ($idcard) ==15?substr_replace ($idcard, "* * *", 8,4):(strlen ($idcard) ==18?substr_replace ($idcard, "* * *", 10,4): "bkjia.c0m hint ID number is not normal! "); |
http://www.bkjia.com/PHPjc/633116.html www.bkjia.com true http://www.bkjia.com/PHPjc/633116.html techarticle A character in a string specified in PHP is replaced with an asterisk we have a function that can be implemented such as Substr,preg_replace,substr_replace and so on, I give these three functions respectively ...