php中转换首字母大写的函数是什么

在php中,想要转换首字母大写,可以使用ucfirst()函数。(相反,想要转换首字母小写,可以使用lcfirst()函数。)

ucfirst 函数能够将字符串的第一个字母转化为大写。语法格式如下:

ucfirst($string)

其中,$string 为需要转化的字符串。

示例:

<?php
    $str = 'hello world!';
    $str = ucfirst($str);
    echo $str.'<br>';
    $str2 = 'HELLO WORLD!';
    $str2 = ucfirst(strtolower($str2));
    echo $str2;
?>

输出结果:

Hello world!
Hello world!
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容