php trim() 函式從字元串的兩端刪除空白字元和其他預定義字元。
基本介紹
- 中文名:php Trim
- 字元串:string
- 字元:charlist
- 回車:trim
語法,例子 1,例子 2,
語法
trim(string,charlist) |
參數 | 描述 |
string | 必需。規定要檢查的字元串。 |
charlist | 可選。規定要轉換的字元串。如果省略該參數,則刪除以下所有字元: |
"\0" - NULL | |
"\t" - tab | |
"\n" - new line | |
"\x0B" - 縱向列表符 | |
"\r" - 回車 | |
" " - 普通空白字元 |
例子 1
<html> <body> <?php $str = " Hello World! "; echo "Without trim: " . $str; echo "<br />"; echo "With trim: " . trim($str); ?> <body> <html> |
輸出:
Without trim: Hello World! With trim: Hello World! |
HTML 源碼:
<html> <body> Without trim: Hello World! <br />With trim: Hello World! </body> </html> |
例子 2
<?php $str = "\r\nHello World!\r\n"; echo "Without trim: " . $str; echo "<br />"; echo "With trim: " . trim($str); ?> |
輸出:
Without trim: Hello World! With trim: Hello World! |
HTML 源碼:
<html> <body> Without trim: Hello World! <br />With trim: Hello World! </body> </html> |
PHP String 函式