"."/> ".">

Home  >  Article  >  Backend Development  >  How to hide name in php

How to hide name in php

藏色散人
藏色散人Original
2022-10-20 10:23:512159browse

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".

How to hide name in php

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,&#39;utf-8&#39;).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!

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