首页 > 其他 > 详细

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

时间:2018-01-16 19:39:46      阅读:197      评论:0      收藏:0      [点我收藏+]

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

<?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);
}


?>

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

原文:https://www.cnblogs.com/richardcastle/p/8297236.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!