Home >Backend Development >PHP Problem >How to replace Chinese string in php
How to implement php to replace Chinese strings: first create a PHP sample file; then set an expression that matches any Chinese character; finally use this expression to replace, that is, replace any characters that appear in the string. Chinese characters, including Chinese symbols.
Recommended: "PHP Video Tutorial"
php Replace the Chinese character in the string
$str="我是chinese,龙的传人!"; //匹配任意中文字符的表达式 $pattern="/[\x7f-\xff]/sim"; $replacement=''; //用该表达式替换,将替换掉字符串中出现的任意中文字符,包括中文符号。 echo 'result:'.preg_replace($pattern,$replacement,$str); //结果为:chinese,!
The above is the detailed content of How to replace Chinese string in php. For more information, please follow other related articles on the PHP Chinese website!