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 批量删除 sql语句

首先要了解sql语句 $SQL="delete from `jb51` where id in (1,2,4)"; 表单大概是: 复制代码 代码如下:<form action=""...

PHP实现二叉树的深度优先与广度优先遍历方法

本文实例讲述了PHP实现二叉树的深度优先与广度优先遍历方法。分享给大家供大家参考。具体如下: #二叉树的广度优先遍历 #使用一个队列实现 class Node { public $...

使用php统计字符串中中英文字符的个数

复制代码 代码如下:<?phpecho $str = "43fdf测试fdsfadaf43543543职工问防盗锁防盗锁5345gfdgd";preg_match_all("/[0...

PHP 中英文混合排版中处理字符串常用的函数

# 判断某个位置是中文字符的左还是右半部分,或不是中文  # 返回值 -1 左 0 不是中文字符 1&nb...

thinkphp autoload 命名空间自定义 namespace

thinkphp autoload 命名空间自定义 namespace

使用thinkPHP过程中,一些自定义的类库和第三方类库需要找一个合适的位置放置,放到系统默认的org文件夹感觉不太好,破坏了thinkPHP的原生目录。 就看了一下官方手册,可以在模块...