Forum Moderators: coopster
They often include apostrophes in the text, which when output to a database-generated page display backslashes in front of the apostrophe. I know this is a fairly common problem but am wondering how to
1) keep the slashes from being added in when the form data is input to the table,
and
2)how to keep them from displaying in the output.
I'm already using "str_replace(Chr(13)," code to display the line breaks from the textarea field...
$bio=mysql_result($result,$i,"bio");
$bio2=str_replace(Chr(13), "<br>", $bio);
wondering how to handle the apostrophes...
any help appreciated in advance..
thanks.
mc
I use addslashes when adding a record to the table, and stripslashes when displaying data from the table.
Here's a reference stripslashes [us2.php.net]
If you have magic quotes on slashes will be added automatically, so ideally you should check before adding the data or you could get two or three slashes instead of one.
if (!get_magic_quotes_gpc())
{
$data = addslashes($data);
}
You do the same when returning the data from the database with stripslashes.
You can also turn the magic quotes functions off if you like. Here are few links that might help:
Addslashes (same as Grandpa`s link)
[uk.php.net...]
Stripslashes
[uk.php.net...]
Get_Magic_Quotes_GPC
[uk.php.net...]
Set_Magic_Quotes_Runtime
[uk.php.net...]
Get_Magic_Quotes_Runtime
[uk.php.net...]
Happy reading.
dc
you don't, you need them there
also if you are escaping data to be inserted into a database then you should use the native escaping function not just addslashes
for mysql
[php.net...]