|
Posted by GamblerZG on 03/29/05 20:12
> 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'/><data><struct>
<var name='pi'><number>3.1415926</number></var><var name='cities'>
<array length='3'><string>Austin</string><string>Novato</string>
<string>Seattle</string></array></var></struct></data></wddxPacket>
(taken from php manual)
to this
a:2:{i:0;d:3.14159260000000006840537025709636509418487548828125;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*.
Navigation:
[Reply to this message]
|