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

php怎么删除空行

PHPz
Release: 2020-06-24 10:53:24
Original
2396 people have browsed it

php怎么删除空行

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

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

 

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

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

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

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

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

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); 
}
Copy after login

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

Related labels:
php
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