Rumah > pembangunan bahagian belakang > tutorial php > PHP删除HTMl标签_PHP教程

PHP删除HTMl标签_PHP教程

WBOY
Lepaskan: 2016-07-20 11:13:35
asal
779 orang telah melayarinya

 <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>
}
Salin selepas log masuk

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440358.htmlTechArticledeletehtml( = ( ); = ( ,"p"); = ("/\t/","", ); = ("/\r\n/","", = ("/\r/","", = ("/\n/","", = ("/ /","", = ("/nbsp; /","", ); ( ); }...
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan