php怎么实现英文转小写
时间:2021-09-24 来源:互联网
今天PHP爱好者给大家带来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爱好者其它相关文章!
-
腾讯视频网页版登录入口-腾讯视频网页版"一起看"功能怎么用 2025-12-27 -
浏览器网页版入口在哪里-热门浏览器网页版官方登录地址 2025-12-27 -
你最好是梗王!谐音爆笑来袭,全网最洗脑的梗都在这,速来get新快乐! 2025-12-27 -
职业小知识最新答案12.23 2025-12-27 -
暗黑破坏神2硬盘版中文下载安装教程-暗黑破坏神2单机版中文最新版本下载 2025-12-27 -
米线是什么梗-底线米线梗全解析 2025-12-27