"."/> ".">
Home >Backend Development >PHP Problem >How to hide name in php
How to hide names in php: 1. Create a PHP sample file; 2. Implement name hiding through the "mb_substr" and "str_repeat" functions, code such as "ee8c5dfc41923bdf9d01fe6db5d2529a".
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
php How to hide name?
Code example:
<?php $user_name = "李二虎"; echo mb_substr($user_name,0,1,'utf-8').str_repeat("*",(strlen($user_name)/2-1)); ?>
This code can hide the last two characters of the name.
Extension:
mb_substr() function returns a part of the string. We have learned the substr() function before. It only targets English characters. If you want to split Chinese characters, you need Use mb_substr().
Note: If the start parameter is negative and length is less than or equal to start, length is 0.
Syntax
mb_substr ( string $str , int $start [, int $length = NULL [, string $encoding = mb_internal_encoding() ]] ) : string
str_repeat() function repeats a string a specified number of times.
Grammar
str_repeat(string,repeat)
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to hide name in php. For more information, please follow other related articles on the PHP Chinese website!