开发者

How can I strip all html using a preg_replace?

开发者 https://www.devze.com 2022-12-25 00:21 出处:网络
strip_tags only catches tags that have a beginning and end开发者_StackOverflow社区 tag.With the strings I\'m working with it\'s causing issues and I need to removed all HTML tags.If you want to clean

strip_tags only catches tags that have a beginning and end开发者_StackOverflow社区 tag. With the strings I'm working with it's causing issues and I need to removed all HTML tags.


If you want to clean some HTML, I would suggest using a real HTML parser, like HTMLPurifier.

Generally speaking, trying to manipulate HTML with regex tends to end badly...


<?php

$html = '<p>Lorem ipsum dolor <br>sit amet, <br />consectetur adipisicing elit</p>';
echo strip_tags($html);

?>

... prints:

Lorem ipsum dolor sit amet, consectetur adipisicing elit

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号