Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Allowing HTML in PHP/MySQL posts?
Closed Thread
Old 06-25-2007, 12:15 PM   #1 (permalink)
 
True Techie

Join Date: May 2006

Location: Chicago IL

Posts: 104

thejeremy

Send a message via AIM to thejeremy
Default Allowing HTML in PHP/MySQL posts?

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.
__________________
CPU: AMD Athlon 64 X2 5200+ Windsor, 2.6 GHz
RAM: CORSAIR XMS2 2GB 240-Pin DDR2
VIDCARD: EVGA PCI-Express x16 GeForce 7900GS 256MB
MOBO: ASUS M2N-SLI Deluxe AM2
HDD: Seagate Barracuda 320GB 7200 RPM SATA

my blog: http://jspot.gotdns.com
thejeremy is offline  
Old 06-25-2007, 02:49 PM   #2 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default Re: Allowing HTML in PHP/MySQL posts?

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 );
__________________
Vormund is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Just heard of Dreamweaver cs3. Replacement for html and css? stainer711 Web Graphics, Design, Digital Images 17 06-19-2007 08:27 AM