首页 > 语言 > PHP > 正文

php正则匹配gb2312和utf-8中文

2024-09-04 11:47:07
字体:大 中 小
来源:转载
供稿:网友
  1. <?php 
  2. $action = trim($_get['action']); 
  3. if($action == "sub") 
  4. { 
  5. $str = $_post['dir']; 
  6. //if(!preg_match("/^[".chr(0xa1)."-".chr(0xff)."a-za-z0-9_]+$/",$str)) //gb2312汉字字母数字下划线正则表达式 
  7. if(!preg_match("/^[x{4e00}-x{9fa5}a-za-z0-9_]+$/u",$str)) //utf-8汉字字母数字下划线正则表达式 
  8. { 
  9.       echo "<font color=red>您输入的[".$str."]含有违法字符</font>"; 
  10. } 
  11. else 
  12. { 
  13.        echo "<font color=green>您输入的[".$str."]完全合法,通过!</font>"; 
  14. } 
  15. } 
  16. ?> 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表