Home > Backend Development > PHP Tutorial > PHP regular retains only Chinese characters, letters and numbers

PHP regular retains only Chinese characters, letters and numbers

不言
Release: 2023-03-24 11:02:01
Original
4527 people have browsed it

This article mainly introduces the php regular expression that only retains Chinese letters and numbers, which has a certain reference value. Now I share it with everyone. Friends in need can refer to it

php regular expression only retains Chinese letters and numbers

//所有中英文符号

$str = "?><?》”\"《喂喂喂555?》《|“:L}{P+_)In thsdff0?><M<>\"s~!@#$%^&*()+_)(*&dsdffsde~!	@#¥%……&*5545445()+——)(*&……%¥#@!~ 电影_后天 230809-peopl.e die我d.(*&^%$#@!!~";

echo match_chinese($str);

function match_chinese($chars,$encoding=&#39;utf8&#39;)
{
    $pattern =($encoding==&#39;utf8&#39;)?&#39;/[\x{4e00}-\x{9fa5}a-zA-Z0-9]/u&#39;:&#39;/[\x80-\xFF]/&#39;;
    preg_match_all($pattern,$chars,$result);
    $temp =join(&#39;&#39;,$result[0]);
    return $temp;
}
Copy after login

             



#

The above is the detailed content of PHP regular retains only Chinese characters, letters and numbers. For more information, please follow other related articles on the PHP Chinese website!

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