Home  >  Article  >  php教程  >  php判断大小写字母函数

php判断大小写字母函数

WBOY
WBOYOriginal
2016-06-13 11:18:032142browse

提供一款简单实例的php判断大小写字母函数哦,它可以查找出一个字符串有多少大写字母有多少小写字母哦,是一个很方便的常用函数。  

提供一款简单实例的php教程判断大小写字母函数哦,它可以查找出一个字符串有多少大写字母有多少小写字母哦,是一个很方便的常用函数。

  function checkcase($str){
              if(preg_match('/^[a-z]+$/', $str)){
                     echo '小写字母';
              }elseif(preg_match('/^[a-z]+$/', $str)){
                     echo '大写字母';
              }
       }

方法二

$str = 'a';
function checkcase1($str){
    $str = ord($str);
    if($str>64&&$str         echo '大写字母';
        return;
    }
    if($str>96&&$str         echo '小写字母';
        return;
    }
    echo '不是字母';
}
function checkcase2($str){
    if(strtoupper($str)===$str){
        echo '大写字母';
    }else{
        echo '小写字母';
    }
}
echo checkcase1($str);
echo checkcase2($str);
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn