Home > php教程 > php手册 > php trim 删除空格字符与指定字符

php trim 删除空格字符与指定字符

WBOY
Release: 2016-06-02 09:14:11
Original
1408 people have browsed it

以前没看trim函数以为他只能删除空白,今天发现它还可以删除"" - null.

"t" - tab ,"n" - new line ,"x0b" - 纵向列表符 ,"r" - 回车 ," " - 普通空白字符,以及用户指定字符.

定义和用法:trim() 函数从字符串的两端删除空白字符和其他预定义字符,可选,规定要转换的字符串,如果省略该参数,则删除以下所有字符:

"" - null,"t" - tab,"n" - new line,"x0b" - 纵向列表符,"r" - 回车," " - 普通空白字符,实例代码如下:

<?php 
$str = " this line containstliberal rn use of whitespace.nn"; 
// first remove the leading/trailing whitespace  
//去掉开始和结束的空白  
$str = trim($str); 
// now remove any doubled-up whitespace  
//去掉跟随别的挤在一块的空白  
$str = preg_replace(&#39;/s(?=s)/&#39;, &#39;&#39;, $str); 
// finally, replace any non-space whitespace, with a space  
//最后,去掉非space 的空白,用一个空格代替  
$str = preg_replace(&#39;/[nrt]/&#39;, &#39; &#39;, $str); 
echo "<pre class="brush:php;toolbar:false">{$str}
Copy after login
"; // "; echo $str1;

   


文章链接:

随便收藏,请保留本文地址!

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template