每個單詞的首字母轉換為大寫: ucwords()
第一個單詞首字母變大寫: ucfirst()
第一個單詞首字母變小寫: lcfirst()
所有 字母變大寫: strtoupper()
例子
代碼如下 復制代碼<?php
echo strtoupper("Hello WORLD!");
?>
輸出:
HELLO WORLD!
第一個單詞首字母變大寫:ucfirst()
代碼如下 復制代碼<?php
$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()
代碼如下 復制代碼<?php
$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()
<?php
$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()
<?php
$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?!
?>