2019獨角獸企業重金招聘Python工程師標準>>>
1、判斷字符串是否全是中文或含有中文
<?php ?
?? ?header('Content-type:text/html; charset=utf-8'); ?
?? ?$str = '你好'; ?
?? ?if(preg_match('/^[\x{4e00}-\x{9fa5}]+$/u', $str)>0){ ?
?? ??? ?echo '全是中文'; ?
?? ?}elseif(preg_match('/[\x{4e00}-\x{9fa5}]/u', $str)>0){ ?
?? ??? ?echo '含有中文'; ?
?? ?} ?
?>?
?
2、去除字符串中的中文字符
<?php ?
?? ?header('Content-type:text/html;charset=utf-8'); ?
?? ?$a = "<a>河蟹)(社會afeowa#$%^!@@#zf吃飯fawgwea漢堡包agho_iawghowi我日)</a>"; ?
?? ?$result = preg_replace('/([\x80-\xff]*)/i','',$a); ?
?? ?var_dump($result);?
? ? //string(43) "afeowa#$%^!@@#zffawgweaagho_iawghowi"
?>?
?