So, i'm making a forum and need to do a few things to the string stored in the variable $body. How would I go about doing this?

A) Not strip, but make where all the HTML/PHP/Javascript/CSS/etc. doesn't work. Like, that way people could share code but it wouldn't execute. Someone suggested using a command like htmlentities($body) (I forgot what it was called) but that didn't work.

B) Spacing. For new lines, i use nl2br($body). I dunno how to explain it, but say the user typed a string like this:

(5 spaces here) is
(10 spaces here) an
(5 spaces here) example
(5 spaces here) string
(2 spaces here) =)

I know the above ^^ is a bad example, but idk how to explain it XD

It would output as (using nl2br):


C) A censor. Basically, take a wordlist, like say I had a file called badwords.txt containing:

It would put them into an array, then if any of the words were found in the string die an error?

thx in advance :)

Member Avatar

1. htmlentities is perfect for this, can't see why it doesn't work for you.

2. html will only show a single space, regardless of how many tabs/spaces you have. You could try the <pre></pre> html tags for code formatting. If you can't use this, try replacing all spaces with the non-breaking space ( &nbsp; ).

3. OK - what's the problem - place them in an array and search for each occurrence.
Personally I'd keep this as a php file, so you can utilize php within it.

$badlist = array("stupid","noob",....);

you can then use preg_match on each or a string function like stripos() - although you must be careful with some of these as they can throw up some strange results - see the php manual. One problem is that you could ban the word 'tit' and inadvertently ban all words with this string in them, e.g. 'supersTITion'.

Anyway, my two-penneth.