標籤:大寫 deb 大小寫 first 英文 tle 轉換 代碼 content
每個單詞的首字母轉換為大寫: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!
?>
第一個單詞首字母變小寫:lcfirst()
代碼如下:<?php
$foo = ‘HelloWorld‘;
$foo = lcfirst($foo); // helloWorld
$bar = ‘HELLO WORLD!‘;
$bar = lcfirst($bar); // hELLO WORLD!
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
?>
所有字母變大寫:strtoupper()
所有字母變小寫:strtolower()
- 1 strtolower() //將字串轉換為小寫形式
- 2 strtoupper() //將字串轉換為大寫形式
- 3 ucfirst() //將字串的第一個字元轉換為大寫形式
- 4 ucwords() //將字串中每一個單詞的首字母轉換為大寫形式
PHP英文字母大小寫轉換函式小結