How it is possible to allow <br /> in strip_tags() or any way I can get around to it?
<?php
$text = '<p>Test <br />paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// Allow <p>, <a>, <br />
echo strip_tags($text, '<p><a><br />');
echo "\n";
// Allow <br /> only
echo strip_tags($text, '<br />');
?>
result:
Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a>
Test paragraph. Other text
Thanks,
Lau
Don’t use a self-closing tag name?
echo strip_tags($text, '<br>');The
strip_tags()function’sallowable_tagsargument takes the allowed tags in the form<tagname>The reason your code didn’t work was because you used<br />instead of<br>.