php实现英文转小写的方法:1、使用lcfirst()函数将第一个英文单词首字母变成小写;2、通过strtolower()函数将所有字母变成小写。
本文操作环境:windows7系统、php7.1版,dell g3电脑
php怎么实现英文转小写?
第一个单词首字母变小写:lcfirst()
代码如下:
<?php$foo = 'helloworld';$foo = lcfirst($foo); // helloworld$bar = 'hello world!';$bar = lcfirst($bar); // hello world!$bar = lcfirst(strtoupper($bar)); // hello world!?>
所有字母变小写:strtolower()
strtolower() 函数把字符串转换为小写,语法是“strtolower(string)”。
注释:该函数是二进制安全的。
相关介绍:
每个单词的首字母转换为大写: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!?>
所有字母变大写:strtoupper()
推荐学习:《php视频教程》
以上就是php怎么实现英文转小写的详细内容。