提供一款简单实例的php判断大小写字母函数,它可以查找出一个字符串有多少大写字母有多少小写字母,是一个很方便的常用函数,代码如下:
function checkcase($str){
if(preg_match('/^[a-z]+$/', $str)){
echo '小写字母';
}elseif(preg_match('/^[a-z]+$/', $str)){
立即学习“PHP免费学习笔记(深入)”;
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);
//开源软件:phpfensi.com
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号