内容导航:
  • PHP检查字符串是否全部是中文用于汉字姓名判断
  • php中文验证码无法显示
  • php代码:怎么样在刚点击完按钮后判断验证码
  • php正则表达式验证中文时候的编码问题
  • {image}

    一、PHP检查字符串是否全部是中文用于汉字姓名判断

    当做一些电商网站的时候,会遇到很多时候购物要实名认证 ,对于国内的人来说 ,输入姓名的时候都要输入汉裂镇字 。汉字而不是中文,为什么这么说 。“。”这个也是中文,所以说汉字比较准确一点。

    分析

    还有一些少数民族里面含有·这个符号 。

    所以算缓基法的核心就是全部扰源谨为中文或者全部为中文并且有·这个符号的两种情况才允许姓名通过验证。

    代码如下:

    二 、php中文验证码无法显示

    匿名用户15 次浏览2015.04.09 提问我来回答提交答案匿名session_start();
    $image=imagecreatetruecolor(200, 60);//创建画布
    $color = imagecolorallocate($image, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255));//随机颜色
    //$color=imagecolorallocate($image, 255, 255, 255);
    imagefill($image, 0, 0, $color);//填充颜色
    //中文验证码
    $fontface="";//确保相同目录下有该字体
    $strdb=array('好','多','人','在','学','习');
    for ($i=0;$i<4;$i++){
    $fontsizecolor=imagecolorallocate($image, mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150));
    $codex=iconv("GB2312","UTF-8",$strdb[mt_rand(0,5)]);//iconv不能转数组 取任意下标
    imagettftext($image, mt_rand(20, 24), mt_rand(-30, 30), (40*$i+20), mt_rand(30, 35), $fontsizecolor, $fontface, $codex);//如果用$code的话 就生成 1+2+3+4 是个汉字的验证码了

    }

    //干扰点
    for ($i=0;$i<200;$i++){
    $pointcolor=imagecolorallocate($image, mt_rand(50, 200), mt_rand(50, 200), mt_rand(50, 200));
    imagesetpixel($image, mt_rand(1, 100), mt_rand(1,20), $pointcolor); //雪花
    }
    //干扰线
    for ($i=0;$i<3;$i++){
    $linecolor=imagecolorallocate($image, mt_rand(50, 200), mt_rand(50, 200), mt_rand(50, 200));
    imageline($image, mt_rand(1, 99), mt_rand(1, 99), mt_rand(1, 99), mt_rand(1, 99), $linecolor);
    }
    ob_clean();
    header("Content-type:image/png");
    imagepng($image);
    imagedestroy($image);session_start(); $image=imagecreatetruecolor(200, 60);//创建画布 $color = imagecolorallocate($image, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255));//随机颜色 //$color=imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $color);//填充颜色 //中文验证码 $fontface="";//确保相同目录下有该字体 $strdb=array('好','多','人','在','学','习'); for ($i=0;$i<4;$i++){ $fontsizecolor=imagecolorallocate($image, mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150)); $codex=iconv("gb2312","utf-8",$strdb[mt_rand(0,5)]);//iconv不能转数组 取任意下标 imagettftext($image, mt_rand(20, 24), mt_rand(-30, 30), (40*$i+20), mt_rand(30, 35), $fontsizecolor, $fontface, $codex);//如果用$code的话 就生成 1+2+3+4 是个汉字的验证码了 } //干扰点 for ($i=0;$i<200;$i++){ $pointcolor=imagecolorallocate($image, mt_rand(50, 200), mt_rand(50, 200), mt_rand(50, 200)); imagesetpixel($image, mt_rand(1, 100), mt_rand(1,20), $pointcolor); //雪花 } //干扰线 for ($i=0;$i<3;$i++){ $linecolor=imagecolorallocate($image, mt_rand(50, 200), mt_rand(50, 200), mt_rand(50, 200)); imageline($image, mt_rand(1, 99), mt_rand(1, 99), mt_rand(1, 99), mt_rand(1, 99), $linecolor); } ob_clean(); header("content- type:image/png"); imagepng($image); imagedestroy($image);

    三 、php代码:怎么样在刚点击完按钮后判断验证码

    如果验证码错误就直接弹出验证码不正确的对话框??验证码一般都是生成一个有时限的session
    用 jquery ajax 取得用户输入的验证码和session比对
    chkcode = $("#chkcode").val();
    $.post("",{chkcode:chkcode},function(data){
    if(data == 0){
    alert('验证码错误!');

    }

    });

    $chkcode = trim($_POST['chkcode']);

    if($chkcode != $_SESSION['s_chkcode']){
    echo '0';

    }你好!

    这个你就要用到ajax了
    单纯的php是没有办法的.

    仅代表个人观点 ,不喜勿喷,谢谢。

    四、php正则表达式验证中文时候的编码问题

    $str = '中华人民共和国abcdefg';
    echo preg_match("/^[\u4e00-\u9fa5_a-zA-Z0-9]{3,15}$",$strName);
    运行一下上面这段穗咐代码,看会有什么提示信息?
    Warning: preg_match(): Compilation failed: PCRE does not support \L, \l, \N, \P, \p, \U, \u, or \X at offset 3 in F:\wwwroot\php\ on line 2
    原来 ,PHP正则表达式中不支持下列 Perl 转义序列:\L, \l, \N, \P, \p, \U, \u, or \X
    在 UTF-8 模式下,允许用“\x{...} ”历好,花括号中的内猜烂纯容是表示十六进制数字的字符串 。原来的十六进制转义序列 \xhh 如果其值大于 127 的话则匹配了一个双字节 UTF-8 字符。
    所以 ,可以这样来解决preg_match("/^[\x80-\xff_a-zA-Z0-9]{3,15}$",$strName);
    复制代码 代码如下:

    本文版权归QU快排Www.seoGurubLog.com 所有,如有转发请注明来出,竞价开户托管,seo优化请联系QQ▲61910465