PHP转换大小写教程基础

小云云
小云云 原创
2023-03-17 17:00:01 1108浏览

为了照顾刚初学php的朋友们,本章内容就和大家分享一下最基础的知识:PHP如何转换大小写,我们会用示例来进行讲解。

strtoupper()

所有字母变大写

strtolower()

所有字母变小写

ucwords()

每个单词的首字母转换为大写

ucfirst()

第一个单词首字母变大写

lcfirst()

第一个单词首字母变小写

示例:

$foo = 'hello world!';
$foo = ucwords($foo);             // Hello World!
 
$bar = 'HELLO WORLD!';
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
 
$foo = 'hello world!';
$foo = ucfirst($foo);             // Hello world!
 
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar);             // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
 
$foo = 'HelloWorld';
$foo = lcfirst($foo);             // helloWorld
 
$bar = 'HELLO WORLD!';
$bar = lcfirst($bar);             // hELLO WORLD!
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!

以上内容就是PHP转换大小写的详解,希望网对大家有帮助。

相关推荐:

python中转换大小写的方法

php字符串首字母转换大小写实例_PHP教程

php字符串首字母转换大小写

以上就是PHP转换大小写教程基础的详细内容,更多请关注php中文网其它相关文章!

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