公告
财富商城
积分规则
提问
发文
2020-02-06 08:23发布
Juvenile、少年°
I want to replace with the 4~8 characters of a string with *,how to do it?
4~8
*
HelloWorld => Hell****ld
<?php $e=str_split("HelloWorld"); $e[3]="*"; $e[4]="*"; $e[5]="*"; echo implode($e); ?>
User can change only the characters that he need.
$str="HelloWorld"; print preg_replace("/^(....)....(.*)/","\\1****\\2",$str);
$string = 'HelloWorld'; for ($i = 4; $i <= 8; ++$i) { $string[$i] = '*'; }
But there is many, many more ways to do that.
You'll need to use substr_replace().
$str = substr_replace("HelloWorld","****",3,-2);
$var="HelloWorld"; $result=substr_replace($var, '****', 4,4 ) . "<br />\n";
use
substr_replace()
like
substr_replace($string, '****', 4 , 4);
read more :
http://php.net/manual/en/function.substr-replace.php
最多设置5个标签!
User can change only the characters that he need.
But there is many, many more ways to do that.
You'll need to use substr_replace().
use
like
read more :
http://php.net/manual/en/function.substr-replace.php