Home  >  Article  >  Backend Development  >  php里如何将所有的 旧商品 中的“旧”字替换成“新”

php里如何将所有的 旧商品 中的“旧”字替换成“新”

WBOY
WBOYOriginal
2016-06-20 12:27:051122browse

php里如何将旧XX中的“旧”字替换成“新”,怎么写代码


回复讨论(解决方案)

echo str_replace('旧','新','旧东西');//新东西

echo str_replace('旧','新','旧东西');//新东西


现在就是需要把字符串的首个汉字改成*,怎么改。比如旧东西,旧商品,过期商品改成*东西,*商品,*期商品,如何写。谢谢啦

$s = '过期商品';echo '*'.mb_substr($s, 1,mb_strlen($s,'utf-8'),'utf-8');

$old_str = '旧东西';$new_str = '新'.mb_substr($old_str, 1, null, 'utf-8');echo $new_str;

Statement:
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