Home > Article > Backend Development > How to hide 6-digit ID number in php
Hide method: 1. Use the "substr_replace($str,str_repeat("*",6), -6)" statement to hide the last 6 digits; 2. Use "substr_replace($str,str_repeat( "*",6),6,6)" statement can hide the middle 6 digits.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, you can use the substr_replace() function and substr_replace() function to hide the ID number and replace the hidden numbers with asterisks.
1. Hide the last 6 digits of the ID number
<?php header("Content-type:text/html;charset=utf-8"); $str = "371515111111116042"; echo substr_replace($str,str_repeat("*",6),-6); ?>
##2. Hide the middle 6 digits of the ID number
<?php header("Content-type:text/html;charset=utf-8"); $str = "371515111111116042"; echo substr_replace($str,str_repeat("*",6),6,6); ?>
3. Hide the first 6 digits of the ID number
<?php header("Content-type:text/html;charset=utf-8"); $str = "371515111111116042"; echo substr_replace($str,str_repeat("*",6),0,6); ?>
Description:
substr_replace() function replaces part of a string with another string; it will replace a string of specified length starting from the specified position. str_repeat() function repeats a string a specified number of times. In the above example, the asterisk "*" character is repeated a specified number of times (consistent with the number of digits to be hidden), and the produced substring is used as the replacement value to replace part of the string. Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to hide 6-digit ID number in php. For more information, please follow other related articles on the PHP Chinese website!