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()

相关文章

深入理解require与require_once与include以及include_once的区别

PHP具有快速、可靠、跨平台应用、源代码开放等特点,使得PHP成为最受欢迎的服务器端Script语言之一。我根据自己在工作中体会到的,向大家介绍PHP使用的心得,希望对大家有所帮助。 利...

sqlyog 中文乱码问题的设置方法

1.在SQLyog下输入下面代码,全部执行 SET character_set_client = utf8; SET character_set_results = gb2312; SE...

PHP动态柱状图实现方法

PHP动态柱状图实现方法

本文实例讲述了PHP动态柱状图实现方法。分享给大家供大家参考。具体分析如下: 1.需求 查询最近一个月的数据总条数和审核通过的条数,做成柱状图 2.实现代码: <!DOCTY...

PHP一些有意思的小区别

单引号'和双引号"的区别:  首先是单引号要比双引号执行效率要高,因为双引号会对内容进行预处理。  例如:'$value' 输出字符 $value...

编写PHP脚本来实现WordPress中评论分页的功能

方法说明 首先来看看可能被用到的方法. 打开文件 wp-includes/link-template.php 你会发现 WordPress 2.7 多了 4 个针对评论分页的方法:...