|
-
Apr 2nd, 2009, 06:34 PM
#1
Thread Starter
Hyperactive Member
-
Apr 2nd, 2009, 06:52 PM
#2
Re: Formatting data being written to MySQL...
1. you could use nl2br(). this replaces every new line to an HTML line break. alternatively, and mostly just because I have a thing against "<br />", I do this:
PHP Code:
$body = "<p>" . $body . "</p>"; $body = str_replace("\n\r", "</p><p>", $body); $body = str_replace("\n", "", $body); $body = str_replace("\r", "", $body);
2. use stripslashes() on any POST/GET variables when you have magic_quotes_gpc on before entering them into your queries.
-
Apr 2nd, 2009, 06:57 PM
#3
Thread Starter
Hyperactive Member
Re: Formatting data being written to MySQL...
kows,
Just to verify.
I use both methods before writing the data away to the database or after retrieving it from the database?
Thanks for the help btw, the stupid software wont allow me to add to your rep
-
Apr 2nd, 2009, 09:10 PM
#4
Re: Formatting data being written to MySQL...
didn't get to check this until just now.
I generally store all information in the database as plain text, and apply any line-breaking methods when displaying it. This makes it easy to be used in different situations, if those situations ever occur. I think that some forum softwares keep a plain text version and an HTML version in the database, so that extra processing is not needed every time they want to display the information. if you want, you could do that, too.
for inserting to the database, I always make a variable calling mysql_real_escape_string() to make sure there are slashes where there needs to be. if you're displaying the information and still have slashes, you can use stripslashes() when you're displaying it.
PHP Code:
<?php $var_to_insert = mysql_real_escape_string($_POST['var']); ?>
<?php $var_to_display = stripslashes($result['var']); echo $var_to_display; ?>
-
Apr 2nd, 2009, 09:25 PM
#5
Thread Starter
Hyperactive Member
Re: Formatting data being written to MySQL...
Cool, off to use my new knowledge to combat the forces of darkness 
Thanks once again kows
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|