Home >php教程 >php手册 >PHP 清除HTML代码、空格、回车换行符的函数

PHP 清除HTML代码、空格、回车换行符的函数

WBOY
WBOYOriginal
2016-06-21 08:57:03974browse

在写采集程序时,往往需要对采集回来的内容进行处理,比如删除HTML代码、去掉多余的空格、删除回车换行符等等。下面就写一个函数来处理。


function DeleteHtml($str)
{
$str = trim($str);
$str = strip_tags($str,"");
$str = ereg_replace("\t","",$str);
$str = ereg_replace("\r\n","",$str);
$str = ereg_replace("\r","",$str);
$str = ereg_replace("\n","",$str);
$str = ereg_replace(" "," ",$str);
return trim($str);
}
 



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