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

WBOY
Release: 2016-06-20 12:27:05
Original
1160 people have browsed it

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


回复讨论(解决方案)

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

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


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

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

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

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template