当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP英文字母大小写转换函数小结

PHP英文字母大小写转换函数小结

2019年03月27日  | 移动技术网IT编程  | 我要评论

每个单词的首字母转换为大写:ucwords()

复制代码 代码如下:
<?php
$foo = 'hello world!';
$foo = ucwords($foo);             // hello world!

$bar = 'hello world!';
$bar = ucwords($bar);             // hello world!
$bar = ucwords(strtolower($bar)); // hello world!
?>

第一个单词首字母变大写:ucfirst()

复制代码 代码如下:
<?php
$foo = 'hello world!';
$foo = ucfirst($foo);             // hello world!

$bar = 'hello world!';
$bar = ucfirst($bar);             // hello world!
$bar = ucfirst(strtolower($bar)); // hello world!
?>

第一个单词首字母变小写:lcfirst()

复制代码 代码如下:
<?php
$foo = 'helloworld';
$foo = lcfirst($foo);             // helloworld

$bar = 'hello world!';
$bar = lcfirst($bar);             // hello world!
$bar = lcfirst(strtoupper($bar)); // hello world!
?>

所有字母变大写:strtoupper()
所有字母变小写:strtolower()

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网