YourNameHere Posted July 27, 2009 Share Posted July 27, 2009 For some reason that I am unaware of, strip_tags is not stripping any tags. here is my code: <? $input=stripslashes(str_replace(array("\r\n", "\n"),"",nl2br(htmlentities($_POST["text"])))); $input2=strip_tags($input, "<br />"); ?> <div style="text-align: left;"> <? echo $input . "<br>"; echo date('F j, Y'); echo "<br>" . $input2; ?> $input works as expected but i am trying to allow nl breaks but is strips those and not any of the other tags. Link to comment https://forums.phpfreaks.com/topic/167669-solved-strip_tags-not-working/ Share on other sites More sharing options...
YourNameHere Posted July 27, 2009 Author Share Posted July 27, 2009 Could it be because of the htmlentities()? Edit: ok, it was (partly) the htmlentities(). However the allowable tags param still isnt working. Link to comment https://forums.phpfreaks.com/topic/167669-solved-strip_tags-not-working/#findComment-884252 Share on other sites More sharing options...
gevans Posted July 27, 2009 Share Posted July 27, 2009 You've already run the data through the htmlentities() function. There is no pure html left in the variable. EDIT: yes Also if you're stripping slashes there I'm guessing you have magic quotes on, which you shouldn't Link to comment https://forums.phpfreaks.com/topic/167669-solved-strip_tags-not-working/#findComment-884256 Share on other sites More sharing options...
YourNameHere Posted July 27, 2009 Author Share Posted July 27, 2009 Also if you're stripping slashes there I'm guessing you have magic quotes on, which you shouldn't magic quotes at runtime is off. gpc is on Link to comment https://forums.phpfreaks.com/topic/167669-solved-strip_tags-not-working/#findComment-884261 Share on other sites More sharing options...
gevans Posted July 27, 2009 Share Posted July 27, 2009 That's unfortunate, problem fixed? Link to comment https://forums.phpfreaks.com/topic/167669-solved-strip_tags-not-working/#findComment-884264 Share on other sites More sharing options...
YourNameHere Posted July 27, 2009 Author Share Posted July 27, 2009 No, it still wont allow <br /> to pass through the strip_tags Link to comment https://forums.phpfreaks.com/topic/167669-solved-strip_tags-not-working/#findComment-884267 Share on other sites More sharing options...
gevans Posted July 27, 2009 Share Posted July 27, 2009 show your new code... Link to comment https://forums.phpfreaks.com/topic/167669-solved-strip_tags-not-working/#findComment-884271 Share on other sites More sharing options...
YourNameHere Posted July 27, 2009 Author Share Posted July 27, 2009 <? $input=stripslashes(str_replace(array("\r\n", "\n"),"",nl2br($_POST["text"]))); $input2=strip_tags($input, '<br />'); ?> <div style="text-align: left;"> <? echo $input . "<br>"; echo date('F j, Y'); echo "<br>" . $input2; ?> Link to comment https://forums.phpfreaks.com/topic/167669-solved-strip_tags-not-working/#findComment-884273 Share on other sites More sharing options...
gevans Posted July 27, 2009 Share Posted July 27, 2009 Use this code; <?php $input = stripslashes( str_replace( array("\r\n", "\n"), "", nl2br($_POST["text"]) ) ); var_dump($input); $input2 = strip_tags($input, '<br />'); echo '<div style="text-align: left;">'; echo $input . "<br>"; echo date('F j, Y'); echo "<br>" . $input2; ?> Then go to view source and post the html back here Link to comment https://forums.phpfreaks.com/topic/167669-solved-strip_tags-not-working/#findComment-884276 Share on other sites More sharing options...
YourNameHere Posted July 28, 2009 Author Share Posted July 28, 2009 string(65) "<strong>Hi,</strong><br /><br />This is <i>just</i> a <u>test</u>" <div style="text-align: left;"><strong>Hi,</strong><br /><br />This is <i>just</i> a <u>test</u><br>July 28, 2009</div> I typed it just like that into the <textarea> <strong>Hi,</strong> This is <i>just</i> a <u>test</u> EDIT: I noticed that, in your code, $input2 wasnt being echoed so I did and it striped all tags including <br /> ...Hi,This is just a testJuly 28, 2009</div> Link to comment https://forums.phpfreaks.com/topic/167669-solved-strip_tags-not-working/#findComment-884667 Share on other sites More sharing options...
YourNameHere Posted July 28, 2009 Author Share Posted July 28, 2009 ok, so I was fooling around with it and tested whether a <strong> tag would be allowed and it was! So there is something wrong with the <br /> format. ...but what? lol Link to comment https://forums.phpfreaks.com/topic/167669-solved-strip_tags-not-working/#findComment-884677 Share on other sites More sharing options...
YourNameHere Posted July 28, 2009 Author Share Posted July 28, 2009 Solved! It was a random test and it worked. Here is my code... <?php $input = stripslashes( str_replace( array("\r\n", "\n"), "", nl2br($_POST["text"]) ) ); var_dump($input); $input2 = strip_tags($input, '<br><br />'); echo '<div style="text-align: left;">'; echo $input . "<br><hr>"; echo $input2 . "<br>"; echo date('F j, Y'); ?> I placed <br> and <br /> in the allowed tags param. Don't know why but it worked together and not separately. Thanks for your help Gevans Link to comment https://forums.phpfreaks.com/topic/167669-solved-strip_tags-not-working/#findComment-884682 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.