Home  >  Article  >  Backend Development  >  How to remove blank lines in php

How to remove blank lines in php

藏色散人
藏色散人Original
2020-09-03 10:06:564189browse

php去除空行的方法:首先通过“preg_replace("/(\r\n|\n|\r|\t)/i", '', $text);”语句去除多余的空格或换行;然后对Html里有连续的空行或tab给正则过滤掉即可。

How to remove blank lines in php

推荐:《PHP视频教程

php:去掉多余的空行

<?php
$str="i   am    a     book\n\n\n\n\nmoth";
//去除所有的空格和换行符
echo preg_replace("/[\s]{2,}/","",$str).&#39;<br>&#39;;
//去除多余的空格和换行符,只保留一个
echo preg_replace("/([\s]{2,})/","\\1",$str);
//去除多余的空格或换行 $text = preg_replace("/(\r\n|\n|\r|\t)/i", &#39;&#39;, $text);
$lastSeveralLineContentsArr = preg_replace("/([ |\t]{0,}[\n]{1,}){2,}/","",$lastSeveralLineContentsArr);
//对Html里有连续的空行或tab给正则过滤掉>
?>

The above is the detailed content of How to remove blank lines in php. For more information, please follow other related articles on the PHP Chinese website!

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