技术社区 / 交流共享 / php判断首字母大小写首或字符串首位大小写

php判断首字母大小写首或字符串首位大小写

置顶
--
2024-03-05 22:04:30 阅读 4708 评论 0
//判断首字母大小写问题
function checkcase($str)
{
    if (preg_match('/^[a-z]+$/', $str)) {
        echo '小写字母';
    } elseif (preg_match('/^[A-Z]+$/', $str)) {
        echo '大写字母';
    }else{
        echo '非法字符';
    }
}
 
function checkcase1($str)
{
    $str = ord($str);
 
    if ($str > 64 && $str < 91) {
        echo '大写字母';
        return;
    }
 
    if ($str > 96 && $str < 123) {
        echo '小写字母';
 
        return;
    }
 
    echo '非法字符';
}
 
function checkcase3($str)
{
    if (strtoupper($str) === $str) {
        echo '大写字母';
    } else {
        echo '小写字母';
    }
}
 
function checkcase4($str)
{
    if (ucfirst($str) === $str) {
        echo '大写字母';
    } else {
        echo '小写字母';
    }
}
 
$str = 'Add';
 
$str = trim($str);
$first = $str[0]; //获取第一个字符  substr($str,0,1)
 
checkcase($first);
exit;

评论(0)

消灭零回复,来发表第一条评论吧
咨询热线
15899929162 0769-82882996 400-6116-696
微信扫码咨询
返回顶部