php代码片段

1.复杂密码检查

        if($account == $password)//密码不能和帐号相同
        {
            return false;
        }
        if(strlen($password) < 8)//密码长度不能小于8位
        {
            return false;
        }
/*        if(substr_count($account, $password) > 0)//密码不能是帐号的一部分
        {
            return false;
        }

        if(substr_count($password, $account) > 0)//密码中不能包含完整的帐号
        {
            return false;
        }

        if(count(array_unique(str_split($password,1))) < 4)//密码至少包含四个不同字符
        {
            return false;
        }
        */
        if(!preg_match('/[A-Za-z0-9_\W]{8,}/',$password)
            || !preg_match('/[A-Z]{1}/',$password)
            || !preg_match('/[a-z]{1}/',$password)
            || !preg_match('/[0-9]{1}/',$password)
            || !preg_match('/[\W_]{1}/',$password)
        )
        {
            return false;
        }

        return true; 

2. php正则匹配中文(不止中文)

<?php

$a = [];

preg_match("![\x7f-\xff]+!",'你妹的', $a);//加号一定要,不然只能匹配中文字符的三分之一
var_dump($a);

 

posted on 2016-06-20 16:05  darkness_1  阅读(150)  评论(0编辑  收藏  举报

导航