php中如何判断字母是大写还是小写
方法一:
使用正则表达式/^[a-z] $/
或者/^[A-Z] $/
进行判断。
实例如下:
function checkcase($str) { if(preg_match('/^[a-z] $/', $str)) { echo '小写字母'; } elseif(preg_match('/^[A-Z] $/', $str)) { echo '大写字母'; } }
相关学习视频分享:php视频教程
方法二:
使用函数“ord()
”和“strtoupper()
”进行判断。
ord()
函数返回字符串中第一个字符的 ASCII 值。
strtoupper()
函数把字符串转换为大写。
实例如下:
<?php $str = 'a'; function checkcase1($str){ $str =ord($str); if($str>64&&$str<91){ echo '大写字母'; return; } if($str>96&&$str<123){ echo '小写字母'; return; } echo'不是字母'; } function checkcase2($str){ if(strtoupper($str)===$str){ echo '大写字母'; }else{ echo '小写字母'; } } echo checkcase1($str); echo checkcase2($str); ?>
推荐相关文章教程:php教程
以上就是php中如何判断字母是大写还是小写的详细内容,更多请关注教程集其它相关文章!
您可能感兴趣的文章:
php中如何判断字母是大写还是小写
php如何小写字母转大写字母
详细讲解PHP的日期时间函数date()
python用函数怎么判断大小写
PHP ord($str)>0x80的自我理解详解
PHP Date()函数详解
php正则表达式完全教程六
php正则表达式完全教程(六)
python如何判断字符是否大写
用python怎么判断字符串是纯英文?