disabling html in forms

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
SublicK
Forum Newbie
Posts: 4
Joined: Wed Dec 18, 2002 4:33 am

disabling html in forms

Post by SublicK »

Hey,

I'm working on a simple forum script, and I want to disable html in the posts. I have been using str_replace() to change the characters '<' '>' etc. to their text code. Is there an easier way to do this?

Code: Select all

function format_content ($content)
   &#123;
     $content = str_replace ("&",  "&",  $content);
     $content = str_replace ("<",  "<",   $content);
     $content = str_replace (">",  ">",   $content);
     $content = str_replace (""", """, $content);
     $content = str_replace ("'",  "'", $content);
     $content = str_replace ("!",  "&#033;", $content);
     $content = str_replace ("|",  "&#124;", $content);
     $content = str_replace ("<br>", "\n", $content);

     return $content;
   &#125;
If there isn't another way, are these all the characters I should look out for? What else should I be careful of?

Thanks
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

SublicK
Forum Newbie
Posts: 4
Joined: Wed Dec 18, 2002 4:33 am

Post by SublicK »

wow, that was quick...

ok, that's deffiently a easier way, thanks
Post Reply