【www.gdgbn.com--正则表达式】

php教程 中文与英语正则表达式

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



php 中文与英语<a href="http://www.gdgbn.com/blist-151-1.html" target="_blank" class="keylink">正则表达式</a>






function funcChinese($str,$num1="",$num2="")//判断中文正则
 {
  if($num1!="" and $num2!=""){
   return (preg_match("/^([x81-xfe][x40-xfe])

{".$num1.",".$num2."}$/",$str))?true:false;
  }else{
   return (!eregi("[^x80-xff]","$str"))?

true:false;
  }
 }

if( $_POST)
{
 if( funcChinese( $_POST["url"] )  )
 {
  echo "是中文";
 }
 else
 {
  exit("不是有效中文");
 }
}
//这个只能一个个字符判断哦,你可以用foreach来处理
?>

本文来源:http://www.gdgbn.com/aspjiaocheng/23940/