tags:

views:

17

answers:

2

I think the title says it, as well...but of course some more explanation

assume i have an array containig strings. if one of my strings contains slashes, like "red/blue/green" there will be troubles when i use the serialize/unserialize function of php and storing/loading the value in a session-variable.

if you have nested large arrays you have to think about escaping every single value, especially if the dimension of the array is not clear. i don't want to run a recursive algorithm over my nested huge arrays for performance reason.

so how can i get that fixed, anyway?

thanks to all helpers ;-)

A: 

Have you tried addslashes() and its other variants?

As for handling arrays of different sizes nested with each other, a recursive function in a for...each loop should do the trick.

Extrakun
well, this does not work, because the slashes are still there in the string
helle
Edited answer regarding arrays
Extrakun
+1  A: 

You could json_encode and json_decode instead of serializing. The end resulting format is not that much different.

This is an alternative so you don't have to create your own function or loop over your large arrray.

Jason McCreary
nice idea! tried that out and if i use json_decode(str_replace(<slash_palce_holder>, "/", <your-string>), true) i get back an assoc array ... works.
helle
Glad it works out. As I said, the formats are pretty close. Serialize is probably a little tigher format.
Jason McCreary