trim — 去除字串开始处与结束处的空白

林继 PHP 技术 4,804 共写了684个字 (2005-06-22 9:01:33) 没有评论 打印 扫描二维码 百度未收录

trim

(PHP 3, PHP 4, PHP 5)

trim — 去除字符串开始处与结束处的空白

说明

string trim ( string str [, string charlist] )

此函式去除字符串开始处与结束处的空白,并且传回去除空白后的字符串。它目前会去除的空白字元有 : “n”、”r”、”t”、”v”、”” 和一般的空白。

  • ” ” (ASCII 32 (0x20)), an ordinary space.

  • “t” (ASCII 9 (0x09)), a tab.

  • “n” (ASCII 10 (0x0A)), a new line (line feed).

  • “r” (ASCII 13 (0x0D)), a carriage return.

  • “” (ASCII 0 (0x00)), the NUL-byte.

  • “x0B” (ASCII 11 (0x0B)), a vertical tab.

You can also specify the characters you want to strip, by means of the charlist parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters.

例子 1. Usage example of trim()

  1. $text = "ttThese are a few words :) ...  ";
  2.  
  3. echo trim($text);           // "These are a few words :) ..."
  4. echo trim($text, " t."); // "These are a few words :)"
  5.  
  6. ?>

注: The optional charlist parameter was added in PHP 4.1.0

另外有RTrim ( 字符串表达式 ):除去字符串右边的空白字
   LTrim ( 字符串表达式 ):除去字符串左边的空白字

参见 ltrim() and rtrim().

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

代码在页面底部,统计标识不会显示,但不影响统计效果
< >