Home > php教程 > php手册 > body text

PHP删除HTMl标签

WBOY
Release: 2016-06-13 11:29:24
Original
1051 people have browsed it

 <span /*</span><span *
 * 取出html标签
 * 
 * @access public
 * @param string str
 * @return string
 * 
 </span><span */</span>
<span function</span> deletehtml(<span $str</span><span ) {
    </span><span $str</span> = <span trim</span>(<span $str</span>); <span //</span><span 清除字符串两边的空格</span>
    <span $str</span> = <span strip_tags</span>(<span $str</span>,"<p>"); <span //</span><span 利用php自带的函数清除html格式。保留P标签</span>
    <span $str</span> = <span preg_replace</span>("/\t/","",<span $str</span>); <span //</span><span 使用正则表达式匹配需要替换的内容,如:空格,换行,并将替换为空。</span>
    <span $str</span> = <span preg_replace</span>("/\r\n/","",<span $str</span><span ); 
    </span><span $str</span> = <span preg_replace</span>("/\r/","",<span $str</span><span ); 
    </span><span $str</span> = <span preg_replace</span>("/\n/","",<span $str</span><span ); 
    </span><span $str</span> = <span preg_replace</span>("/ /","",<span $str</span><span );
    </span><span $str</span> = <span preg_replace</span>("/  /","",<span $str</span>);  <span //</span><span 匹配html中的空格</span>
    <span return</span> <span trim</span>(<span $str</span>); <span //</span><span 返回字符串</span>
}
Copy after login

 

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template