Home  >  Article  >  Backend Development  >  php trim函数 ltrim函数 rtrim函数的差异

php trim函数 ltrim函数 rtrim函数的差异

WBOY
WBOYOriginal
2016-06-13 11:52:381229browse

php trim函数 ltrim函数 rtrim函数的区别

大家都知道php的trim()函数,ltrim()函数,rtrim()函数都可以去除掉空格,那么三者在用法上有什么不同的区别那?现在就来为大家一一介绍一下。
1.php trim()函数是去掉所有的空格(其实准确的来说是去掉字符串两次的所有空格),例如:
$str=" love 59biye ";<br>echo ("---".trim($str)."---");//输出---love 59biye---<br>2.php ltrim()函数是去掉字符串左侧的空格,例如:
$str=" love 59biye ";<br>echo ("---".ltrim($str)."---");//输出---love 59biye ---<br>3.php rtrim()函数是去掉字符串右侧的空格,例如:
$str=" love 59biye ";<br>echo ("---".ltrim($str)."---");//输出--- love 59biye---<br>好了,大家看出他们的具体的区别了吧。

Statement:
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