Home > Backend Development > PHP Tutorial > PHP使用trim函数去除字符串左右空格及特殊字符实例_PHP

PHP使用trim函数去除字符串左右空格及特殊字符实例_PHP

WBOY
Release: 2016-05-28 11:49:28
Original
1033 people have browsed it

本文实例讲述了PHP使用trim函数去除字符串左右空格及特殊字符的方法。分享给大家供大家参考,具体如下:

PHP中trim()函数定义如下

trim(string,charlist)

参数说明如下:

string 必需。规定要检查的字符串。

charlist

可选。规定从字符串中删除哪些字符。如果被省略,则移除以下所有字符:
"\0" - NULL
"\t" - 制表符
"\n" - 换行
"\x0B" - 垂直制表符
"\r" - 回车
" " - 空格

示例代码如下:

<&#63;php
 $str="\r\r(:@_@   提供大量优秀脚本与素材下载  @_@:)   ";
 echo trim($str);
 echo "<br/>";
 echo trim($str,"\r\r(: :)");
&#63;>

Copy after login

运行结果如下:

(:@_@  提供大量优秀脚本与素材下载 @_@:)
@_@  提供大量优秀脚本与素材下载 @_@

Copy after login

希望本文所述对大家PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template