用十六进制判断字符串,用来验证一些规则(例:判断大小写数字是否存在)

栗子:判断字符中是否存在大小写和数字;

<?php 

$res = 0x00;
$lit = 0x01;
$big = 0x02;
$num = 0x04;

$a = checkstr('Gj6',$res,$lit,$big,$num);
if(($a&$lit)==$lit) echo '存在小写';
if(($a&$big)==$big) echo '存在大写';
if(($a&$num)==$num) echo '存在数字';

//1\2\4\5\6\3\7
function checkstr($str,$res,$lit,$big,$num){
    if(preg_match('/[a-z]/', $str)){
        //存在小写
        $res|=$lit;
    }
    if(preg_match('/[A-Z]/', $str)){
        //存在大写
        $res|=$big;
    }
    if(preg_match('/[0-9]/', $str)){
        //存在数字
        $res|=$num;
    }
	return $res;
    //return base_convert($res,2,10);
}


?>
posted @ 2018-01-16 16:16  小酱油  阅读(625)  评论(0编辑  收藏  举报