php strip_tags: allows <br />?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

php strip_tags: allows <br />?

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php strip_tags: allows <br />?

Post by requinix »

Question: you use <p> and not <p />, <a> and not <a />, so why a <br />?
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

Re: php strip_tags: allows <br />?

Post 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
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: php strip_tags: allows <br />?

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php strip_tags: allows <br />?

Post 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...
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: php strip_tags: allows <br />?

Post by Eran »

oh, sorry, missed that one :)
Didn't go through his entire code
Post Reply