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. |