Re: [PHP] Storing data structires in DB
You are looking for serialize here. I bet you'd be better off with an existing XML format for something like this though. WDDX is an unusual extension for most of the hosting providers. And writing my own XML serialization mechanism is an overkill. Moreover, XML is not-compact, harder to edit and probably slower to parse. Compare this: wddxPacket version='1.0'header comment='PHP'/datastruct var name='pi'number3.1415926/number/varvar name='cities' array length='3'stringAustin/stringstringNovato/string stringSeattle/string/array/var/struct/data/wddxPacket (taken from php manual) to this a:2:{i:0;d:3.141592606840537025709636509418487548828125;i:1;a:3:{i:0;s:6:Austin;i:1;s:6:Novato;i:2;s:6:Seattle;}} (Number is given exactly as it was output by serialize. What a happy coincidence.) and to this array(3.1415926,array('Austin','Novato','Seattle')) (which could be reduced even more by elliminating the outer array() statement) I'm surprised that there is no way to safely serialize and unserialize things using the same syntax as PHP itself uses. I can, of course, write PHP data structure parser in PHP, but that's twisted way of doing it, and it will be *slow*. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Storing data structires in DB
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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Storing data structires in DB
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Storing data structires in DB
Output of serialize() is barely readable and definetely is not suited for manual editing. It is quite simple to create var_export() clone that does not add junk to it's output. But then I would need to exec() the string to get a data structure back, which is bad security practice. Is there any good way to store/retrieve data structures (multidimetional arrays) to/from database? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Storing data structires in DB
GamblerZG mailto:[EMAIL PROTECTED] on Thursday, March 24, 2005 1:15 PM said: Output of serialize() is barely readable and definetely is not suited for manual editing. [snip /] Is there any good way to store/retrieve data structures (multidimetional arrays) to/from database? Maybe I missed something... So why is serialize not any good? Is it because of the way it looks when it's printed? Chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Storing data structires in DB
GamblerZG wrote: Output of serialize() is barely readable and definetely is not suited for manual editing. It is quite simple to create var_export() clone that does not add junk to it's output. But then I would need to exec() the string to get a data structure back, which is bad security practice. Is there any good way to store/retrieve data structures (multidimetional arrays) to/from database? Huh? 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. But that's just me. -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php