Home > php教程 > php手册 > php正则匹配gb2312和utf-8中文

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 09:54:57
Original
1134 people have browsed it

$action = trim($_get['action']);
if($action == "sub")
{
$str = $_post['dir'];
//if(!preg_match("/^[".chr(0xa1)."-".chr(0xff)."a-za-z0-9_]+$/",$str)) //gb2312汉字字母数字下划线正则表达式
if(!preg_match("/^[x{4e00}-x{9fa5}a-za-z0-9_]+$/u",$str)) //utf-8汉字字母数字下划线正则表达式
{
      echo "您输入的[".$str."]含有违法字符";
}
else
{
       echo "您输入的[".$str."]完全合法,通过!";
}
}
?>

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template