Re: Parsing serialized PHP arrays in "C"
| From: | Rasmus Lerdorf | Date: | Sun, 22 Oct 2006 05:52:40 +0000 |
| Subject: | Re: Parsing serialized PHP arrays in "C" | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-243432@lists.php.net to get a copy of this message | ||
Kevin Wilcox wrote:
I have a feeling this may be the wrong group to ask this question, but I thought that if it is, someone can point me in the right direction. I'm working on a application written in "C" that needs to parse and understand php arrays that have been serialized and stored in a MySQL table. I started writing the parser and realized its not a trivial task. I'm wondering if there is any source code in C to do what I'm looking for? I googled many different combinations of keywords and nothing useful came up. I even looked at the code in ext/standard/var_unserializer.c, and I don't think what will port to a stand alone application without extensive modifications.Why not? It is a rather simple re2c parser. Don't look at var_unserializer.c, look at var_unserializer.re and read up on re2c. http://re2c.org/ You would obviously want to replace the creation of internal PHP data types with whatever you want to unserialize to in your app, but I don't see how you would find any code somewhere else where you wouldn't need to yank out the destination code from since that is going to be the unique part in each implementation. And if you use the same re2c grammar that PHP uses, it will be correct. Using any other implementation likely wouldn't be. Of course, I also wouldn't suggest using serialized PHP for a target that wasn't PHP. Why don't you look at json or perhaps wddx instead? -Rasmus