Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中隐藏/替换字符串的一部分?_Php_String_Replace - Fatal编程技术网

如何在PHP中隐藏/替换字符串的一部分?

如何在PHP中隐藏/替换字符串的一部分?,php,string,replace,Php,String,Replace,我想使用自己的函数隐藏字符串的一部分。例如:$string=hello这是我的密码;。如果我的函数是HashPartOfString$string,我想把我的字符串放在这个函数中,并有如下输出:hel******************ord。我该怎么做呢?如果您一直想显示第一个和最后三个字母,以及介于两者之间的*字母,那么您可以通过sub-string和string-concat方法来完成 $str = "hello this is my password"; echo

我想使用自己的函数隐藏字符串的一部分。例如:$string=hello这是我的密码;。如果我的函数是HashPartOfString$string,我想把我的字符串放在这个函数中,并有如下输出:hel******************ord。我该怎么做呢?

如果您一直想显示第一个和最后三个字母,以及介于两者之间的*字母,那么您可以通过sub-string和string-concat方法来完成

$str = "hello this is my password"; 
echo substr($str,0,3)."******".substr($str,(strlen($str))-3,3);

可能类似于$str=srfegkeruehkgu;回声子序列$str,0,3.******。子序列$str,strlen$str-3,3