Allowing HTML in PHP/MySQL posts?

Status
Not open for further replies.

thejeremy

In Runtime
Messages
104
Location
Chicago IL
I'm working on my own website for personal use, nothing on a large-scale, and I'm coding it all from scratch just because that's how I like to do things. I have some of the basic PHP/MySQL foundation stuff down, like logging in/out and whatnot, but I want to be able to make posts onto the main page by typing in a large textbox just like how I'm making this post now. I want to allow HTML tags within this textbox without screwing everything up. I also want to make it ok to use apostrophes in words. I've tried this and it causes lots of issues with the surrounding PHP code. Do I need to write my own regular expression replacement functions using preg_replace or is there some easier way to do this?

Thanks in advance.
 
You can use addslashes( ) to make any input safe for comparisons/queries etc., such as:
$comment = addslashes( $_POST['comment'] );
...and then using stripslashes( ) when outputting the content later on.

A thing to note, when typing in (this) text box, line breaks are the invisible newline character, \n, so you'd need to replace them with <br/>:
$subject = str_replace( "\n", "<br/>", $subject );
 
Status
Not open for further replies.
Back
Top Bottom