adam84 Posted August 11, 2007 Share Posted August 11, 2007 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??? Quote Link to comment https://forums.phpfreaks.com/topic/64446-removing-html-tags/ Share on other sites More sharing options...
Orio Posted August 11, 2007 Share Posted August 11, 2007 I think you should check out strip_tags(). Orio. Quote Link to comment https://forums.phpfreaks.com/topic/64446-removing-html-tags/#findComment-321310 Share on other sites More sharing options...
Fadion Posted August 11, 2007 Share Posted August 11, 2007 or <a href="http://www.php.net/manual/en/function.htmlentities.php">htmlentities()</a> Quote Link to comment https://forums.phpfreaks.com/topic/64446-removing-html-tags/#findComment-321311 Share on other sites More sharing options...
lewis987 Posted August 11, 2007 Share Posted August 11, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/64446-removing-html-tags/#findComment-321312 Share on other sites More sharing options...
marcus Posted August 11, 2007 Share Posted August 11, 2007 $txt will always equal itself, so why bother redefining it? Quote Link to comment https://forums.phpfreaks.com/topic/64446-removing-html-tags/#findComment-321318 Share on other sites More sharing options...
Fadion Posted August 11, 2007 Share Posted August 11, 2007 maybe he means $txt = $txt2. Anyway: and make sure your form uses the method get rather than post.. post is more secure Guess u mean 'make sure your form uses post rather the get' Quote Link to comment https://forums.phpfreaks.com/topic/64446-removing-html-tags/#findComment-321329 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.