strtoupper(string) 把字符串轉換爲大寫。該函數是二進制安全的。php
strtolower(string) 把字符串轉換爲小寫。該函數是二進制安全的。html
ucwords(string) 把字符串中每一個單詞的首字符轉換爲大寫。該函數是二進制安全的。數組
ucfirst(string) 把字符串中的首字符轉換爲大寫。該函數是二進制安全的。安全
lcfirst(string) 把字符串中的首字符轉換爲小寫。該函數是二進制安全的。函數
string | 必需。規定要轉換的字符串。 |
echo strtoupper("Hello WORLD."); //HELLO WORLD. echo strtolower("Hello WORLD."); //hello world. echo ucwords("hello world!"); //Hello World! echo ucfirst("hello world!"); //Hello world! echo lcfirst("Hello world!"); //hello world!
substr(string,start,length) 返回字符串的一部分。spa
string | 必需。規定要返回其中一部分的字符串。 |
start | 必需。規定在字符串的何處開始。code
|
length | 可選。規定被返回字符串的長度。默認是直到字符串的結尾。htm
|
註釋:若是 start 參數是負數且 length 小於或等於 start,則 length 爲 0。字符串
echo substr("Hello world",6); //world echo substr("Hello world",0,-1)."<br>"; //Hello worl
substr_replace(string,replacement,start,length) 把字符串的一部分替換爲另外一個字符串。string
string | 必需。規定要檢查的字符串。 |
replacement | 必需。規定要插入的字符串。 |
start | 必需。規定在字符串的何處開始替換。
|
length | 可選。規定要替換多少個字符。默認是與字符串長度相同。
|
註釋:若是 start 參數是負數且 length 小於或者等於 start,則 length 爲 0。
註釋:該函數是二進制安全的。
echo substr_replace("Hello","world",0); //world echo substr_replace("Hello world","Shanghai",6); //Hello Shanghai echo substr_replace("Hello world","Shanghai",-5); //Hello Shanghai echo substr_replace("world","Hello ",0,0); //Hello world $replace = array("1: AAA","2: AAA","3: AAA"); echo implode(" ",substr_replace($replace,'BBB',3,3)); //1: BBB 2: BBB 3: BBB
nl2br(string,xhtml)
string | 必需。規定要檢查的字符串。 |
xhtml | 可選。布爾值,表示是否使用兼容 XHTML 換行:
|
在字符串中的每一個新行(\n)以前插入 HTML 換行符(<br> 或 <br />)
echo nl2br("One line.\nAnother line."); //One line. //Another line.
explode(separator,string,limit) 把字符串打散爲數組。
separator | 必需。規定在哪裏分割字符串。 |
string | 必需。要分割的字符串。 |
limit | 可選。規定所返回的數組元素的數目。 可能的值:
|
"separator" 參數不能是空字符串。該函數是二進制安全的。
implode() 返回由數組元素組合成的字符串。