PHP和MySQL的刪除空白函數介紹

來源:互聯網
上載者:User

    對 ltrim()和rtrim(),從其英語解釋來看:


以下是引用片段:
PHP為:Strip whitespace (or other characters)
MySQL為:space characters removed


    顯然,PHP還可以有“other characters”,而且PHP的函數還可以用第二個參數自訂要刪除的字元。

    對“other characters”,手冊解釋為:


以下是引用片段:

 代碼如下 複製代碼
" " (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.

 


    不過,MySQL的trim()函數也增加了對其他字元的刪除。具體請見下面從手冊上摘抄的解釋。

= = = = = = = = = = = = = 方便閱讀的分隔線  = = = = = = = = = = = = = = = =

    以下為MySQL的函數解釋

 代碼如下 複製代碼

    LTRIM(str)

    Returns the string str with leading space characters removed.

以下是程式碼片段:

 代碼如下 複製代碼

mysql> SELECT LTRIM('  barbar');
        -> 'barbar'

 

    This function is multi-byte safe.

    RTRIM(str)

    Returns the string str with trailing space characters removed.


以下是程式碼片段:

 代碼如下 複製代碼

mysql> SELECT RTRIM('barbar   ');
        -> 'barbar'

    This function is multi-byte safe.

    TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRIM([remstr FROM] str)

    Returns the string str with all remstr prefixes or suffixes removed. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. remstr is optional and, if not specified, spaces are removed.


以下是程式碼片段:

 代碼如下 複製代碼

mysql> SELECT TRIM('  bar   ');
        -> 'bar'
mysql> SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx');
        -> 'barxxx'
mysql> SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx');
        -> 'bar'
mysql> SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz');
        -> 'barx'

    This function is multi-byte safe.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.