按书上代码调试有些问题,修正成如下正确代码:
当前网页必须为UTF-8格式才能正适用:
<?php
if($_GET['act']=="validate"){
//echo $_POST['name'];
$t=mb_convert_encoding($_POST['name'],"GBK","utf-8"); //若当前网页为gb2312格式,则需要注释掉这一行
if(preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/",$t))
echo "yes";
else
echo "no";
die();
}
?>
<form action="?act=validate" method="post">
<input name="name" type="text" />
<input type="submit" value="yz" />
</form>