Page 1 of 1

special characters in array

Posted: Tue Jul 29, 2008 8:25 am
by aceconcepts
Hi,

I am trying to store some plain text in a serialized array that will be stored in a database.

The string i'm trying to store in an array may contain appostraphes, back slashes - anaything really.

How can I store these characters in a serialized array?

I've tried
htmlentities($str, ENT_QUOTES),
addslashes($str)

they are implementing their function but i am unable to retrieve the string from the array.

I have also unserialized the array - just in case you're wondering.

Any ideas?

Re: special characters in array

Posted: Tue Jul 29, 2008 9:01 am
by it2051229
dont know what you're up to.. but if you want to store any character into the mysql database.. you can make use of mysql_escape_string($whateverYouWantToStore).. but for arrays? it's possible to store anything.. give me your code and let me look at it

Re: special characters in array

Posted: Tue Jul 29, 2008 9:04 am
by aceconcepts
I'm already using sprintf and mysql_real_escape_string.

The database is ok, it's just the special characters that are giving me problems. Because my array has to be serialized in order to be stored correctly in the db, the additional formatting applied by serialize() conflicts with the special characters.

Re: special characters in array

Posted: Tue Jul 29, 2008 9:13 am
by it2051229
How about a rawurlencode(); I usually use this to encode special characters when passing it into a url cause of ajax applications. Give it a try.

Re: special characters in array

Posted: Tue Jul 29, 2008 9:18 am
by dml
As long as it's correctly escaped, it should be possible to store serialised data in the database. Do you have some test code that demonstrates what you're trying to do, what you expect to happen, and what's actually happening?

Edit: didn't read all the replies. I'm repeating what it2051229 said.

Re: special characters in array

Posted: Tue Jul 29, 2008 9:47 am
by aceconcepts
rawurlencode() has worked well.

Thanks for all the input :D