Home > Backend Development > PHP Problem > How to replace Chinese string in php

How to replace Chinese string in php

藏色散人
Release: 2023-03-03 22:46:01
Original
3465 people have browsed it

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,!
Copy after login

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!

Related labels:
php
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