special characters in array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

special characters in array

Post 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?
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: special characters in array

Post 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: special characters in array

Post 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.
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: special characters in array

Post 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.
dml
Forum Contributor
Posts: 133
Joined: Sat Jan 26, 2008 2:20 pm

Re: special characters in array

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: special characters in array

Post by aceconcepts »

rawurlencode() has worked well.

Thanks for all the input :D
Post Reply