[php]trim — 去除字符串首尾處的空白字符(或者其他字符)
此函數返回字符串 str 去除首尾空白字符後的結果。如果不指定第二個參數,trim() 將去除這些字符:
" " (ASCII 32 (0x20)),普通空格符。
"\t" (ASCII 9 (0x09)),製表符。
"\n" (ASCII 10 (0x0A)),換行符。
"\r" (ASCII 13 (0x0D)),回車符。
"\0" (ASCII 0 (0x00)),空字節符。
"\x0B" (ASCII 11 (0x0B)),垂直製表符。
官方範例
<?php
$text = "\t\tThese are a few words :) ... ";
$binary = "\x09Example string\x0A";
$hello = "Hello World";
var_dump($text, $binary, $hello);
print "\n";
$trimmed = trim($text);
var_dump($trimmed);
$trimmed = trim($text, " \t.");
var_dump($trimmed);
$trimmed = trim($hello, "Hdle");
var_dump($trimmed);
// 清除 $binary 首位的 ASCII 控制字符
// (包括 0-31)
$clean = trim($binary, "\x00..\x1F");
var_dump($clean);
?>
以上例程會輸出:
string(32) " These are a few words :) ... "
string(16) " Example string
"
string(11) "Hello World"
string(28) "These are a few words :) ..."
string(24) "These are a few words :)"
string(5) "o Wor"
string(14) "Example string"
公告版位
礁溪溫泉套房,位於宜蘭縣礁溪國小旁,近麥當勞,離礁溪火車站、首都客運、葛瑪蘭汽車客運約5分鍾車程,礁溪溫泉套房出租,您不需要再行添購傢俱,只需要帶幾件衣服,就能輕輕鬆鬆住進礁溪溫泉套房,天天在礁溪溫泉套房洗溫泉唷!意洽:游媽媽,電話0939711360,4500~4900元/月
- Jul 07 Thu 2011 09:49
[php]trim — 去除字符串首尾處的空白字符(或者其他字符)
全站熱搜
留言列表