Home  >  Article  >  Backend Development  >  How to hide 6-digit ID number in php

How to hide 6-digit ID number in php

青灯夜游
青灯夜游Original
2022-04-26 14:17:124180browse

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.

How to hide 6-digit ID number in php

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

How to hide 6-digit ID number in php

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

How to hide 6-digit ID number in php

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

How to hide 6-digit ID number in php

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!

Statement:
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