Home > Backend Development > PHP Problem > How to hide name in php

How to hide name in php

藏色散人
Release: 2023-03-17 07:26:01
Original
2199 people have browsed it

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

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));
?>
Copy after login

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
Copy after login

str_repeat() function repeats a string a specified number of times.

Grammar

str_repeat(string,repeat)
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template