Jump to content

[SOLVED] strip_tags not working


YourNameHere

Recommended Posts

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

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

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>

 

:facewall:

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.