龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

PHP将字符串首字母大小写转换

时间:2017-06-24 02:22来源:网络整理 作者:网络 点击:
分享到:
PHP将字符串首字母大小写转换 每个单词的首字母转换为大写:ucwords()1amp;lt;?php2$fooamp;nbsp;=amp;nbsp;#39;hello world!#39;;3$fooamp;nbsp;= ucwords($foo);amp;nbsp;amp;nbsp;amp;nbsp;amp;nbsp;amp;nbsp;amp;nbsp;amp;nbsp;

每个单词的首字母转换为大写:ucwords() 1<?php2$foo = 'hello world!';3$foo = ucwords($foo);             // Hello World!4 5$bar = 'HELLO WORLD!';6$bar = ucwords($bar);             // HELLO WORLD!7$bar = ucwords(strtolower($bar)); // Hello World!8?>  

第一个单词首字母变大写:ucfirst() 1<?php2$foo = 'hello world!';3$foo = ucfirst($foo);             // Hello world!4 5$bar = 'HELLO WORLD!';6$bar = ucfirst($bar);             // HELLO WORLD!7$bar = ucfirst(strtolower($bar)); // Hello world!8?>  

第一个单词首字母变小写:lcfirst() 1<?php2$foo = 'HelloWorld';3$foo = lcfirst($foo);             // helloWorld4 5$bar = 'HELLO WORLD!';6$bar = lcfirst($bar);             // hELLO WORLD!7$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!8?>  

所有 字母变大写:strtoupper()

所有 字母变小写:strtolower()

精彩图集

赞助商链接