首页 > 其他 > 详细

判断汉字

时间:2014-03-09 15:05:42      阅读:484      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
<?php
$action = trim($_GET[‘action‘]);
if($action == "sub")
{
    $str = $_POST[‘dir‘];


    $str=iconv(‘GBK‘,‘utf-8‘,$str);

//if(!preg_match("/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_]+$/",$str)) //GB2312汉字字母数字下划线正则表达式
    //preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$str)

    if(!preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$str)) //UTF-8汉字正则表达式
    {
        echo"<font color=red>您输入的[".$str."]含有违法字符</font>";
    }
    else
    {
        echo "<font color=green>您输入的[".$str."]完全合法,通过!</font>";
    }
}


?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<form method="POST" action="?action=sub">
    输入字符(数字,字母,汉字,下划线):
    <input type="text" name="dir" value="">
    <input type="submit" value="提交">
</form>
</body>
</html>
bubuko.com,布布扣

判断汉字,布布扣,bubuko.com

判断汉字

原文:http://www.cnblogs.com/afei-happy/p/3586023.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!