PHP將字符串首字母大小寫轉換
每個單詞的首字母轉換為大寫:ucwords()
1 |
<?php |
2 |
$foo = 'hello world!' ; |
3 |
$foo = ucwords( $foo ); // Hello World! |
4 |
5 |
$bar = 'HELLO WORLD!' ; |
6 |
$bar = ucwords( $bar ); // HELLO WORLD! |
7 |
$bar = ucwords( strtolower ( $bar )); // Hello World! |
8 |
?> |
第一個單詞首字母變大寫:ucfirst()
1 |
<?php |
2 |
$foo = 'hello world!' ; |
3 |
$foo = ucfirst( $foo ); // Hello world! |
4 |
5 |
$bar = 'HELLO WORLD!' ; |
6 |
$bar = ucfirst( $bar ); // HELLO WORLD! |
7 |
$bar = ucfirst( strtolower ( $bar )); // Hello world! |
8 |
?> |
第一個單詞首字母變小寫:lcfirst()
1 |
<?php |
2 |
$foo = 'HelloWorld' ; |
3 |
$foo = lcfirst( $foo ); // helloWorld |
4 |
5 |
$bar = 'HELLO WORLD!' ; |
6 |
$bar = lcfirst( $bar ); // hELLO WORLD! |
7 |
$bar = lcfirst( strtoupper ( $bar )); // hELLO WORLD! |
8 |
?> |
所有 字母變大寫:strtoupper()
所有 字母變小寫:strtolower()
本文由用戶 jjui 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!