[英]replace every other character in a string with php
在php中,有一种快速的方法可以用其他东西替换字符串中的所有其他字符(非空格)? 我四处搜寻,但没有找到解决方案。
采取这样的事情:
$str = "This is my example string!"
最后是这样的:
$result = "T*i* i* m* e*a*p*e s*r*n*!
简单的preg_replace()
解决方案:
$str = "This is my example string!";
$result = preg_replace('/(\S)\S/', '$1*', $str);
print_r($result);
输出:
T*i* i* m* e*a*p*e s*r*n*!
\\S
代表非空白字符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.