Page 1 of 1

php strip_tags: allows <br />?

Posted: Sat Sep 25, 2010 8:28 am
by lauthiamkok
Hi,

How it is possible to allow

Code: Select all

<br />
in strip_tags() or any way I can get around to it?

Code: Select all

<?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

Re: php strip_tags: allows <br />?

Posted: Sat Sep 25, 2010 8:29 am
by requinix
Question: you use <p> and not <p />, <a> and not <a />, so why a <br />?

Re: php strip_tags: allows <br />?

Posted: Sat Sep 25, 2010 8:34 am
by lauthiamkok
tasairis wrote:Question: you use <p> and not <p />, <a> and not <a />, so why a <br />?
thanks for the thought. got the answer now

Code: Select all

echo strip_tags($text, '<br>');

thanks! :D

Re: php strip_tags: allows <br />?

Posted: Sat Sep 25, 2010 8:57 am
by Eran
tasairis wrote:Question: you use <p> and not <p />, <a> and not <a />, so why a <br />?
This is the XHTML syntax for self closing tags

Re: php strip_tags: allows <br />?

Posted: Sat Sep 25, 2010 8:35 pm
by requinix
pytrin wrote:
tasairis wrote:Question: you use <p> and not <p />, <a> and not <a />, so why a <br />?
This is the XHTML syntax for self closing tags
...Yeah, I know. It was a rhetorical question to get OP to think for a second...

Re: php strip_tags: allows <br />?

Posted: Sat Sep 25, 2010 8:59 pm
by Eran
oh, sorry, missed that one :)
Didn't go through his entire code