这次给大家带来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英文字母大小写转换如何实现的详细内容。