为了照顾刚初学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字符串首字母转换大小写