一聚教程网:一个值得你收藏的教程网站

热门教程

php中英文字符转换大小字代码

时间:2022-06-24 15:23:33 编辑:袖梨 来源:一聚教程网

每个单词的首字母转换为大写: ucwords()
第一个单词首字母变大写: ucfirst()
第一个单词首字母变小写: lcfirst()
所有 字母变大写: strtoupper()

例子

 代码如下 复制代码

echo strtoupper("Hello WORLD!");
?>

输出:

HELLO WORLD!

第一个单词首字母变大写:ucfirst()

 代码如下 复制代码

$foo = 'where are doing?!';
$foo = ucfirst($foo);             // where are doing?!

$bar = 'where are doing?!';
$bar = ucfirst($bar);             // where are doing?!
$bar = ucfirst(strtolower($bar)); // where are doing?!
?>

所有 字母变小写: strtolower()

 代码如下 复制代码

$str = "Mary Had A Little Lamb and She LOVED It So";
$str = strtolower($str);
echo $str; // Prints mary had a little lamb and she loved it so
?>


每个单词的首字母转换为大写:ucwords()

 代码如下 复制代码

$foo = 'where are doing?!';
$foo = ucwords($foo);             // Where are doing?!

$bar = 'where are doing?!';
$bar = ucwords($bar);             // Where are doing?!
$bar = ucwords(strtolower($bar)); // Where are doing?!
?>

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

 代码如下 复制代码

$foo = 'HelloWorld';
$foo = lcfirst($foo);             // where are doing

$bar = 'where are doing?!';
$bar = lcfirst($bar);             // where are doing?!
$bar = lcfirst(strtoupper($bar)); // where are doing?!
?>

热门栏目