Home > Backend Development > PHP Problem > How to remove blank lines in php

How to remove blank lines in php

藏色散人
Release: 2023-03-05 17:16:01
Original
4226 people have browsed it

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给正则过滤掉>
?>
Copy after login

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!

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