Home >Backend Development >PHP Tutorial >php怎么删除空行

php怎么删除空行

PHPz
PHPzOriginal
2016-06-13 10:14:142397browse

php怎么删除空行

php源码之删除空格空行换行

本文章向大家介绍php删除字符串中空格空行和换行,主要使用到php的preg_replace函数和正则表达式的相关知识,需要的朋友可以参考一下本文章。

 

1、去除所有的空格和换行符

echo preg_replace("/[\s]{2,}/","",$str).&#39;<br>&#39;;

preg_replace("/(\r\n|\n|\r|\t)/i", &#39;&#39;, $text)

 

2、去除多余的空格和换行符,只保留一个

echo preg_replace("/([\s]{2,})/","\\1",$str);

 

3、清除换行符,清除回车换行,去除换行函数,空格,html标签

function DeleteHtml($str) 
{ 
/* http://www.manongjc.com/article/1592.html */
$str = str_replace("<br/>","",$str);
$str = str_replace("\t","",$str); 
$str = str_replace("\r\n","",$str); 
$str = str_replace("\r","",$str); 
$str = str_replace("\n","",$str); 
return trim($str); 
}

更多相关技术文章,请访问PHP中文网

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