Forum Moderators: coopster

Message Too Old, No Replies

Stripslash - addslash? - problem with apostrophe in text

         

michlcamp

3:53 am on Oct 18, 2005 (gmt 0)

10+ Year Member



I have a form that members to my site fill out with bio information, then the form data is posted to a database table.

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

grandpa

4:26 am on Oct 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Take a look the addslashes and stripslashes functions of PHP.

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]

dreamcatcher

8:11 am on Oct 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, as Grandpa says, uses both of those functions.

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

jatar_k

3:35 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> 1) keep the slashes from being added in when the form data is input to the table

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...]