Jump to content

Removing HTML Tags


adam84

Recommended Posts

I am using ajax, so I am manipulate the text with either php(prefer) or javascript.

 

I have a text area where the user enters whatever. They click send and a 'js' function gets called and it calls my sendRequest function and sends over the data to my php file to be insert into my db.

 

What I want to do is remove any of the html/js tags I can. The only thing I want to keep is the spacing the user enters (line spacing).

 

My php file - I have tried many different ways, but none of them seem to work


$txt = $_GET['text'];

$stuff = array("\n","\r");
$txt = str_replace($stuff, "<br />");
echo strip_tags($txt, '<br />');

 

So using the code above if I enter:

<b>Test</b>

This is a test

 

The Results is:

TestThis is a test

 

I've tried another method using 'preg_match', but i am getting an error b/c of the function.

by the way i am using php 4.4.4

Any ideas what is going on???

 

Link to comment
https://forums.phpfreaks.com/topic/64446-removing-html-tags/
Share on other sites

how about trying this:

 

$txt = $_GET['text'];
$txt = strip_tags($txt);

//just to make sure it is the correct value
$txt = $txt

echo nl2br($txt);

 

that will make every:

\n

to:

<br />

 

how it helps...

 

and make sure your form uses the method get rather than post..

 

post is more secure

Link to comment
https://forums.phpfreaks.com/topic/64446-removing-html-tags/#findComment-321312
Share on other sites

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.