...

View Full Version : Allowing/Disallowing HTML in Posts with PHP



Taylor_1978
11-02-2003, 08:41 AM
Hiya,

I am building a forum and I want to allow non-premium members to be able to post simple messages, where they CANNOT post HTML, but when they hit enter twice, it records as a new paragraph. Obviously it does it as you type it out in the textarea, and it looks like this in the database, but when recalling it - it comes out as one long line.

At the moment it allows HTML, and you would have to type in <P> to get a new paragraph... how do I stop html and yet allow the parapraph without typing <P>.

Thanks in advance! :thumbsup:
Taylor.
www.ysuperleague.com

missing-score
11-02-2003, 11:33 AM
i would use:




$str = htmlentities($str, ENT_QUOTE);
$str = nl2br($str);

missing-score
11-02-2003, 11:42 AM
just another thing i forgot to mention. nl2br() will convert newlines to <br />. If you need XHTML compliance but are using an earlier version of php, nl2br will stop your page validating because it will replace newlines with <br>.

if your on an older version of php that does this, it can be overcame by:




$str = preg_replace("\n", '<br />', $str);

Taylor_1978
11-02-2003, 06:47 PM
Hiya,

Thanks for that - I assume though that this is just for allowing new lines/paragraphs... How do I stop HTML from being read altogether?

Thanks in advance! :thumbsup:
Taylor.
www.ysuperleague.com

EDIT: Nevermind - I found out the easy way - by putting it in! LOL - Thanks!

missing-score
11-02-2003, 06:52 PM
ok




preg_replace("/\\<([\\/]{,1}(.*))\\>/is", "", $str);



try that.

Dalziel
11-03-2003, 02:14 PM
I've never used it but isn't there a function called striptags() http://www.danleitch.co.uk/smileys/conf03.gif

missing-score
11-03-2003, 04:27 PM
yes, you're right :o

i searched php.net for strip_html :p

Dalziel
11-06-2003, 04:46 PM
Originally posted by missing-score
yes, you're right :o

i searched php.net for strip_html :p

I mentioned that I'd never used it because I thought you might need the function do something different, I knew it actually existed.

Glad I could help for once, I'm not exactly a PHP genius
http://www.danleitch.co.uk/smileys/lol04.gif



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum