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