在php中如果我們要把字符轉換成大小寫直接使用strtolower或者strtoupper即可,但是要首字母要轉換大小寫我們需要使用ucwords相關函數.
首字母變大寫: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!Vevb.com
- ?>
第一個詞首字母小寫lcfirst(),代碼如下:
- $foo = 'HelloWorld';
- $foo = lcfirst($foo); // helloWorld
- $bar = 'HELLO WORLD!';
新聞熱點
疑難解答