天天看點

PHP英文字母大小寫轉換函數小結

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