匹配中文

<?
$str = "測試中文";
echo $str;
echo "<hr>";
//if (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) { //只能在GB2312狀況下使用
//if (preg_match("/^[\x7f-\xff]+$/", $str)) { //兼容gb2312,utf-8  //判斷字符串是否全是中文
if (preg_match("/[\x7f-\xff]/", $str)) {  //判斷字符串中是否有中文
echo "正確輸入";
} else {
echo "錯誤輸入";
}
?>

圖片描述

相關文章
相關標籤/搜索