PHP和MySQL的删除空白函数介绍
2019/10/10/17:33:58 阅读:1856 来源:谷歌SEO算法 标签:
SEO技术
作为黄金搭档,PHP和MySQL都有自己的删除空白函数,而且函数名字也一样:trim(),ltrim(),rtrim(),当然,作为编程语言,PHP删除空白函数更为强大.
对 ltrim()和rtrim(),从其英语解释来看:
以下是引用片段:
PHP为:Strip whitespace (or other characters)
MySQL为:space characters removed
显然,PHP还可以有“other characters”,而且PHP的函数还可以用第二个参数自定义要删除的字符.
对“other characters”,手册解释为,以下是引用片段:
- ""(ASCII32(0x20)),anordinaryspace.
- "t"(ASCII9(0x09)),atab.
- "n"(ASCII10(0x0A)),anewline(linefeed).
- "r"(ASCII13(0x0D)),acarriagereturn.
- ""(ASCII0(0x00)),theNUL-byte.
- "x0B"(ASCII11(0x0B)),averticaltab.
不过,MySQL的trim()函数也增加了对其他字符的删除,具体请见下面从手册上摘抄的解释.
以下为MySQL的函数解释:
LTRIM(str),Returns the string str with leading space characters removed.
以下是代码片段:
- mysql>SELECTLTRIM('barbar');
- ->'barbar'
- Thisfunctionismulti-bytesafe.
- RTRIM(str)
- Returnsthestringstrwithtrailingspacecharactersremoved.
以下是代码片段:
- mysql>SELECTRTRIM('barbar');
- ->'barbar'
- Thisfunctionismulti-bytesafe.
- TRIM([{BOTH|LEADING|TRAILING}[remstr]FROM]str),TRIM([remstrFROM]str)
- Returnsthestringstrwithallremstrprefixesorsuffixesremoved.IfnoneofthespecifiersBOTH,LEADING,orTRAILINGisgiven,BOTHisassumed.remstrisoptionaland,ifnotspecified,spacesareremoved.
以下是代码片段,代码如下:
- mysql>SELECTTRIM('bar');
- ->'bar'
- mysql>SELECTTRIM(LEADING'x'FROM'xxxbarxxx');
- ->'barxxx'
- mysql>SELECTTRIM(BOTH'x'FROM'xxxbarxxx');
- ->'bar'
- mysql>SELECTTRIM(TRAILING'xyz'FROM'barxxyz');
- ->'barx'--phpfensi.com
- Thisfunctionismulti-bytesafe.
热门评论