您现在的位置是:首页 > PHP基础

李清波 2017-10-11 PHP基础 2863 复制当前网址

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!


文章来源:https://www.liqingbo.com/blog-1472.html

上一篇:PHP5.6 和PHP7.0区别

下一篇:flush

评论