开发者

How to handle slashes in strings in arrays for serialize function in php?

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 ;-)


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜