php trim() 函式从字元串的两端删除空白字元和其他预定义字元。
基本介绍
- 中文名php Trim
- 字元串string
- 字元charlist
- 回车trim
语法
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 函式