PHP保留中文字符串

<?php 
$str='你好,我来自外太空F3032星球'; 
preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $str, $matches);//只要汉字

preg_match_all('/[a-zA-Z0-9\x{4e00}-\x{9fff}]+/u', $str, $matches_1);//只保留汉字和数字和英文字符

$str = join('', $matches[0]);

$str_1 = join('', $matches_1[0]);

echo $str;
echo $str_1;
?>
0
0

发表回复

Your email address will not be published. Required fields are marked *.

*
*