ITPub博客

首页 > IT职业 > IT职场 > php首字母小写怎么转大写

php首字母小写怎么转大写

IT职场 作者:R-B 时间:2021-09-11 09:33:59 0 删除 编辑

php首字母小写转大写的方法:1、创建一个PHP示例文件;2、使用“ucwords($foo)”方法将每个单词的首字母转换为大写;3、使用“ucfirst($foo);”方法将第一个单词首字母变大写。

本文操作环境:Windows7系统、PHP7.1版本、Dell G3电脑

php首字母小写怎么转大写?

php首字母小写转大写的方法

每个单词的首字母转换为大写:ucwords()

<?php
$foo = 'hello world!';
$foo = ucwords($foo);             // Hello World!
 
$bar = 'HELLO WORLD!';
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>

ucwords() 函数把字符串中每个单词的首字符转换为大写。

第一个单词首字母变大写:ucfirst()

<?php
$foo = 'hello world!';
$foo = ucfirst($foo);             // Hello world!
 
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar);             // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>

ucfirst() 函数把字符串中的首字符转换为大写。

推荐:《PHP视频教程》

以上就是php首字母小写怎么转大写的详细内容,更多请关注php中文网其它相关文章!

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4560/viewspace-2827294/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-09-03

  • 博文量
    183
  • 访问量
    10153