PHP判断字符串中是否含有中文
2个回答
展开全部
一,判断全是中文
$str="'324是";
if(!eregi("[^\x80-\xff]","$str")){
echo "全是中文";
}else{
echo "不是";
}
二,判断含有中文
$str = "中文";
if (preg_match("/[\x7f-\xff]/", $str)) {
echo "含有中文";
}else{
echo "没有中文";
}
或
$pattern = '/[^\x00-\x80]/';
if(preg_match($pattern,$str)){
echo "含有中文";
}else{
echo "没有中文";
}
如果还有问题可以去后盾网论坛问题求助专区,希望我的回答对你有帮助
$str="'324是";
if(!eregi("[^\x80-\xff]","$str")){
echo "全是中文";
}else{
echo "不是";
}
二,判断含有中文
$str = "中文";
if (preg_match("/[\x7f-\xff]/", $str)) {
echo "含有中文";
}else{
echo "没有中文";
}
或
$pattern = '/[^\x00-\x80]/';
if(preg_match($pattern,$str)){
echo "含有中文";
}else{
echo "没有中文";
}
如果还有问题可以去后盾网论坛问题求助专区,希望我的回答对你有帮助
2015-12-04
展开全部
<?
$str = "测试中文";
echo $str;
echo "<hr>";
//if (<a href="https://www.baidu.com/s?wd=preg_match&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9PW9hPjF-nWbzPW0vPAmz0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtkPHfknjc1P1ckrj6LnjR4rH6L" target="_blank" class="baidu-highlight">preg_match</a>("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) { //只能在GB2312情况下使用
//if (<a href="https://www.baidu.com/s?wd=preg_match&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9PW9hPjF-nWbzPW0vPAmz0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtkPHfknjc1P1ckrj6LnjR4rH6L" target="_blank" class="baidu-highlight">preg_match</a>("/^[\x7f-\xff]+$/", $str)) { //兼容gb2312,utf-8 //判断字符串是否全是中文
if (<a href="https://www.baidu.com/s?wd=preg_match&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9PW9hPjF-nWbzPW0vPAmz0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtkPHfknjc1P1ckrj6LnjR4rH6L" target="_blank" class="baidu-highlight">preg_match</a>("/[\x7f-\xff]/", $str)) { //判断字符串中是否有中文
echo "正确输入";
} else {
echo "错误输入";
}
?>
$str = "测试中文";
echo $str;
echo "<hr>";
//if (<a href="https://www.baidu.com/s?wd=preg_match&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9PW9hPjF-nWbzPW0vPAmz0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtkPHfknjc1P1ckrj6LnjR4rH6L" target="_blank" class="baidu-highlight">preg_match</a>("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) { //只能在GB2312情况下使用
//if (<a href="https://www.baidu.com/s?wd=preg_match&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9PW9hPjF-nWbzPW0vPAmz0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtkPHfknjc1P1ckrj6LnjR4rH6L" target="_blank" class="baidu-highlight">preg_match</a>("/^[\x7f-\xff]+$/", $str)) { //兼容gb2312,utf-8 //判断字符串是否全是中文
if (<a href="https://www.baidu.com/s?wd=preg_match&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9PW9hPjF-nWbzPW0vPAmz0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtkPHfknjc1P1ckrj6LnjR4rH6L" target="_blank" class="baidu-highlight">preg_match</a>("/[\x7f-\xff]/", $str)) { //判断字符串中是否有中文
echo "正确输入";
} else {
echo "错误输入";
}
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询