Method code for replacing characters according to specified identifier and length in php

不言
Release: 2023-04-03 21:28:01
Original
1420 people have browsed it

The content of this article is about the method code of replacing characters according to the specified logo and length in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

/** * 按指定标识及长度替换字符 * @param $str * @param int $start 开始的位数 * @param int $end 后面保留的位数 * @param string $mode * @return mixed */function _str_repeat($str=null, $start = 4, $end = 4, $mode = '*'){ if(!empty($str)){ $length = mb_strlen($str,'utf8')-$start-$end; $repeat = str_repeat($mode, $length); // 按个数输出标识 return substr_replace($str, $repeat, $start, $length); } return ''; }
Copy after login

Use

默认按手机的格式: _str_repeat('13522223333', 4, 4), 从第4位开始加*,到后面保留的位数 135****3333 _str_repeat('220181199112300078', 6, 8)220181****12300078
Copy after login

Related recommendations:

php code to intercept a string according to the specified length

php function to convert numbers to strings of specified length

The above is the detailed content of Method code for replacing characters according to specified identifier and length 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!