Re: Storing data structires in DB

From: Date: Sun, 27 Mar 2005 02:24:00 +0000
Subject: Re: Storing data structires in DB
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-211646@lists.php.net to get a copy of this message
GamblerZG wrote:
Why would you _manually_ edit a serialized array??? One would think you would UNSERIALIZE (http://us4.php.net/unserialize) the serialized array *before* working with the data.
Well, I guess my initial posting was a bit misleading. I'm writing a content management system, and that system needs to give its users ability to create arbitrary data structures. Suppose users should be able to create hyperlinked menus. Each menu entry must have text, URL and, possibly, title. There are several ways to achieve such functionality. 1) Write big and ugly interface that does only that – creates menus. Not very smart, because tomorrow users might need to create nested categories or some other things. 2) Invent your own syntax for menu programming and write small, but still ugly procedure that parses that syntax. 3) Invent your own syntax for data structure programming, and write function that parses it into PHP data structures. Almost a good solution, but then I would need some way to store, retrieve and edit data. 4) Use something that already exists. If I can, I would prefer to stick with 4. After all, PHP has var_export() and eval(). The problem is, var_export() stuffs its output with junk (extra commas, newlines, spaces), and eval() executes any code.
You are looking for serialize here. I bet you'd be better off with an existing XML format for something like this though. -Rasmus

« previous php.general (#211646) next »