php首字母小写怎么转大写

藏色散人
发布: 2023-03-12 09:18:02
原创
2022 人浏览过

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

php首字母小写怎么转大写

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

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

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

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

<?php
$foo = &#39;hello world!&#39;;
$foo = ucwords($foo);             // Hello World!
 
$bar = &#39;HELLO WORLD!&#39;;
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>
登录后复制

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

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

<?php
$foo = &#39;hello world!&#39;;
$foo = ucfirst($foo);             // Hello world!
 
$bar = &#39;HELLO WORLD!&#39;;
$bar = ucfirst($bar);             // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>
登录后复制

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

推荐:《PHP视频教程

以上是php首字母小写怎么转大写的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
php
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!