Home  >  Article  >  Backend Development  >  PHP function to determine uppercase and lowercase letters_PHP tutorial

PHP function to determine uppercase and lowercase letters_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:01:531097browse

Provide a simple example of the PHP function for judging uppercase and lowercase letters. It can find out how many uppercase letters and lowercase letters there are in a string. It is a very convenient and commonly used function. ​

Provide a simple example of the PHP tutorial to determine the uppercase and lowercase letters function. It can find out how many uppercase letters and how many lowercase letters a string has. It is a very convenient and commonly used function.

function checkcase($str){
If(preg_match('/^[a-z]+$/', $str)){
echo 'lowercase letters';
                 }elseif(preg_match('/^[a-z]+$/', $str)){
echo 'uppercase letters';
              }
}

Method 2

$str = 'a';
function checkcase1($str){
$str = ord($str);
If($str>64&&$str<91){
           echo 'uppercase letters';
         return;
}
If($str>96&&$str<123){
           echo 'lowercase letters';
         return;
}
echo 'Not a letter';
}
function checkcase2($str){
If(strtoupper($str)===$str){
           echo 'uppercase letters';
}else{
           echo 'lowercase letters';
}
}
echo checkcase1($str);
echo checkcase2($str);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445425.htmlTechArticleProvides a simple example of PHP function to determine upper and lower case letters. It can find out how many uppercase letters there are in a string. How many lowercase letters are there in a letter? It is a very convenient and commonly used function. Mention...
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