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
Share on other sites

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

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.