PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

php首字母小写怎么转大写

藏色散人
藏色散人 原创
2021-09-01 10:32:18 1869浏览

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

本文操作环境: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视频教程

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。