PHP4使用者手冊:函數-trim_PHP

來源:互聯網
上載者:User
關鍵字 函數 手冊 使用者 trim ASCII trimmed
手冊

TABLE border=0 cellPadding=0 cellSpacing=0 height="100%" width="100%">

(PHP 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)), 斷行符號符;

"\0" (ASCII 0 (0x00)), Null 字元;

"\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()例子

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

?>

參見ltrim()和rtrim().

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.