Home  >  Article  >  php教程  >  php 正则只保留 汉字 字母 数字

php 正则只保留 汉字 字母 数字

PHP中文网
PHP中文网Original
2016-05-22 18:27:011416browse

跳至

$str = "?><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;
}

                   

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
Previous article:PHP 微信卡券Next article:csv文件画图