disabling HTML tags in textarea?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex7900
Forum Newbie
Posts: 4
Joined: Wed Nov 26, 2008 4:42 pm

disabling HTML tags in textarea?

Post by alex7900 »

I want to know how to disable html tags in a textarea, for example if you type this:

Code: Select all

<Hey whats up?>
it wont show anything when i submit it since the browser will detect it as an html command

its for a comment system, and Im no professional with php :P
this is what im using:

Code: Select all

 
<form action='blahblah.blahblah'>
<textarea cols="43" rows="11" name='blahblahblah'></textarea>
<input type='submit'>
</form>
and it is recieved, in the next page, and printed like this:

Code: Select all

$text=S_POST['blahblahblah'];
echo "$text";
that WILL display the text, but it will let the user use html tags, and that will definitly lead to someone playing with the layouts, or even using php :banghead:
im not asking for BBcode or anything(unless you know how! :o ), but i just want to let the user use html tags without actually using html

EDIT:
also, i wanna know how to automatically detect linebreaks, because in the editor even if you press enter a million times, all the text will be on one line :(
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: disabling HTML tags in textarea?

Post by Syntac »

draco
Forum Newbie
Posts: 7
Joined: Wed Nov 26, 2008 11:45 pm

Re: disabling HTML tags in textarea?

Post by draco »

You should also check out the strip_tags() function. You can also only allow certain tags through.
alex7900
Forum Newbie
Posts: 4
Joined: Wed Nov 26, 2008 4:42 pm

Re: disabling HTML tags in textarea?

Post by alex7900 »

thanks, that helped :D
i used:
htmlspecialchars()
and
str_replace() - which i found by playing around in that site :P
Post Reply