PHP4使用者手冊:函式->trim (轉)

worldblog發表於2007-12-10
PHP4使用者手冊:函式->trim (轉)[@more@]

( 3, PHP 4 >= 4.0.0)

trim -- 去除一個字串開始和結尾的空白

描述

string trim (string str [, string charlist])

注意:第二個引數用在PHP 4.1.0

這個返回str字串被去除首尾空白後的新字串。不帶第二個引數trim() 將去除下列字元:

  • " " (ASCII 32 (0x20)), 空格;

  • "t" (ASCII 9 (0x09)), 製表符;

  • "n" (ASCII 10 (0x0A)), 換行符;

  • "r" (ASCII 13 (0x0D)), 回車符;

  • "" (ASCII 0 (0x00)), 空字元;

  • "x0B" (ASCII 11 (0x0B)), 垂直製表符。

你可以透過charlist引數指定你想去除的字元。Simply list all characters that you want to be stripped. With .. you can specify a range of characters.

例1. trim()例子

$trimmed = "These are a few words :) ..." $trimmed = trim($text," t."); // $trimmed = "These are a few words :)" $clean = trim($binary,"x00..x1F"); // trim the ASCII control characters at the beginning and end of $binary // (from 0 to 31 inclusive) ?>


參見指令碼類/PHP/PHP手冊/fancy/function.ltrim.html">ltrim()和.



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-991076/,如需轉載,請註明出處,否則將追究法律責任。

相關文章