PHP英文字母大小写转换如何实现

php中世界最好的语言
php中世界最好的语言 原创
2023-03-27 08:22:01 4040浏览

这次给大家带来PHP英文字母大小写转换如何实现,PHP英文字母大小写转换实现的注意事项有哪些,下面就是实战案例,一起来看一下。

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

<?php
$foo = 'hello world!';
$foo = ucwords($foo);             // Hello World!
$bar = 'HELLO WORLD!';
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(
strtolower
($bar)); // Hello World!
?>

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

<?php
$foo = 'hello world!';
$foo = ucfirst($foo);             // Hello world!
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar);             // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>

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

<?php
$foo = 'HelloWorld';
$foo = lcfirst($foo);             // helloWorld
$bar = 'HELLO WORLD!';
$bar = lcfirst($bar);             // hELLO WORLD!
$bar = lcfirst(
strtoupper
($bar)); // hELLO WORLD!
?>

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

以上共介绍了五个英文字母大小写转换函数的函数,分别为ucwords、ucfirst、lcfirst、strtoupper、strtolower,各有所用。

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

php判断远程图片能否被调用

PHP按行读取文件时删除换行符操作详解

以上就是PHP英文字母大小写转换如何实现的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。