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

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

<?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 '存在数字';

//1245637
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);
}


?>
原文地址:https://www.cnblogs.com/richardcastle/p/8297236.html