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

yipeiwu_com5年前PHP代码库

每个单词的首字母转换为大写: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!
?>

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

复制代码 代码如下:
<?php
$foo = 'HelloWorld';
$foo = lcfirst($foo);             // helloWorld

$bar = 'HELLO WORLD!';
$bar = lcfirst($bar);             // hELLO WORLD!
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
?>

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

相关文章

PHP 将dataurl转成图片image方法总结

PHP 将dataurl转成图片image方法 使用canvas 生成的图片,是使用dataurl的,php无法直接通过file_put_contents方法保存到本地电脑,需要做一下转...

JoshChen_web格式编码UTF8-无BOM的小细节分析

JoshChen_web格式编码UTF8-无BOM的小细节分析

但是在开发的过程中,发现一个小细节的问题,必须要打开F12才能看到的,原来,在head头部里面的所有引用的东西以及title等等,全部都跑到body里面去了,苦思冥想,百度、google...

定义php常量的详解

常量可以理解为值不变的变量。常量值被定义后,在脚本的其他任何地方都不能被改变。一个常量由英文字母、下划线、和数字组成,但  数字不能作为首字母出现。在php中使用defaine...

php实现的xml操作类

本文实例讲述了php实现的xml操作类。分享给大家供大家参考,具体如下: <?php /* 使用方法: $test=new xml(); $test->new_x...

php自动加载的两种实现方法

php自动载方法有两种. 第一种方案用__autoload,这个函数较简单,也较弱. 但有一问题没有解决, 就是在include前判断文件是否存在的问题. 复制代码 代码如下: set_...