Introduction to deleting blank functions in PHP and MySQL

Source: Internet
Author: User
Tags mysql functions
As a gold partner, PHP and MySQL both have their own blank deletion functions, and the function names are the same: trim (), ltrim (), rtrim (). Of course, as a programming language, PHP is more powerful in deleting blank functions.

As a gold partner, PHP and MySQL both have their own blank deletion functions, and the function names are the same: trim (), ltrim (), rtrim (). Of course, as a programming language, PHP is more powerful in deleting blank functions.

For ltrim () and rtrim (), the English explanation is as follows:


The following is a reference clip:
PHP: Strip whitespace (or other characters)
MySQL: space characters removed


Obviously, PHP can also have "other characters", and PHP functions can also use the second parameter to customize the characters to be deleted.

For "other characters", the manual is interpreted:


The following is a reference clip:

The Code is as follows:
"" (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.
"\ 0" (ASCII 0 (0x00), the NUL-byte.
"X0B" (ASCII 11 (0x0B), a vertical tab.


However, the MySQL trim () function also adds the deletion of other characters. For more information, see the following description in the manual.

================= Separation line for easy reading ===========================

The following describes MySQL functions.

The Code is as follows:

LTRIM (str)

Returns the string str with leading space characters removed.

The following is a code snippet:

The Code is as follows:

Mysql> select ltrim ('barbar ');
-> 'Barbar'

This function is multi-byte safe.

RTRIM (str)

Returns the string str with trailing space characters removed.


The following is a code snippet:

The Code is as follows:

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.


The following is a code snippet:

The Code is as follows:

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.