教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 PHP英文字母大小写转换函数

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

发布时间:2018-05-12   编辑:jiaochengji.com
介绍几个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中怎么将大写字母转换为小写字母
python如何把小写字母变成大写字母
php 字母大小写转换的实例总结
php中如何判断字母是大写还是小写
php5 字符串处理函数汇总
php中强制字母转换大小写的方法有哪些
php字符串过滤与转换函数有哪些
php中英文字符转换大小字代码

关键词: 大小写转换  中文大小写   
[关闭]
~ ~