HOME
DOMAIN
WEB HOST
AUTO Site
VPS SERVER
CLOUD HOST
SERVER
HK HOST
AGENT
SERVICE
php正则中文表达式,实例代码如下:
<?php $str = "abc一二三cde"; echo preg_replace('/[^x4e00-x9fa5]/i'," ",$str); $str = "php编程"; if (preg_match("/^[x4e00-x9fa5]+$/u",$str)) { print("该字符串全部是中文"); } else { print("该字符串不全部是中文"); } $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 "<font color=red>您输入的[".$str."]含有违法字符</font>"; } else{ echo "<font color=green>您输入的[".$str."]完全合法,通过!</font>"; } } ?> <form method="post" action="?action=sub"> 输入字符(数字,字母,汉字,下划线): <input type="text" value=""> <input type="submit" value="提交"> </form>