Home  >  Article  >  Backend Development  >  How to replace Chinese string in php

How to replace Chinese string in php

藏色散人
藏色散人Original
2020-08-07 09:45:403363browse

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.

How to replace Chinese string in php

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!

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