PHP中ltrim与rtrim去除左右空格及特殊字符实例_PHP

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

本文实例分析了PHP中ltrim与rtrim去除左右空格及特殊字符的用法。分享给大家供大家参考,具体如下:

一、PHP中ltrim定义如下:

ltrim(string,charlist)

参数说明:

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

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

二、PHP中rtrim定义如下:

rtrim(string,charlist)

参数说明如下:

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

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

三、用法示例如下:

<&#63;php
$str=" (:@_@  提供大量优秀脚本及素材供读者下载 \n\n @_@:)  ";
 echo ltrim($str);
 echo "<br>";
 echo ltrim($str," (:@_@ ");
 echo "<br/>";
 echo rtrim($str);
 echo "<br>";
 echo rtrim($str," @_@:) ");
&#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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!