I have a table with a load of rows of serialized arrays that I plan to request and pass it to JavaScript
.
The problem is - is it possible to unserialize
with JavaScript rather than PHP ?
Otherwise I will have to load all the rows, loop them and unserialize them and assign them to a temporary PHP array and then json_encode it back to JavaScript which seems highly inefficient if I can send the data still serialized so that JavaScript can unserialize the data when it needs to.
Is there a built in Javascript function that does it or will I have to loop the rows in PHP before I encode it?
Note I am not using jQuery.
EDIT: Example of my serialized data in PHP from my table:
a:8:{i:0;a:2:{i:0;i:10;i:1;i:11;}i:1;a:2:{i:0;i:9;i:1;i:11;}i:2;a:2:
{i:0;i:8;i:1;i:11;}i:3;a:2:{i:0;i:8;i:1;i:10;}i:4;a:2:{i:0;i:8;i:1;i:9;}i:5;a:2:
{i:0;i:8;i:1;i:8;}i:6;a:2:{i:0;i:8;i:1;i:7;}i:7;a:2:{i:0;i:8;i:1;i:6;}}
PHP unserialize() Function$data = serialize(array("Red", "Green", "Blue")); echo $data . "<br>"; $test = unserialize($data);
unserialize() function The unserialize() converts serialized data to actual data. Example of php. js unserialize() function: In the following web document, unserialize() function converts a serialize data to actual format.
PHP: unserialize() function The unserialize() converts to actual data from serialized data. The serialized string. Return value: Converted value.
serialize() returns a string containing a byte-stream representation of any value that can be stored in PHP. unserialize() can use this string to recreate the original variable values. Using serialize to save an object will save all variables in an object.
Php.js has javascript implementations of unserialize and serialize:
http://phpjs.org/functions/unserialize/
http://phpjs.org/functions/serialize/
That said, it's probably more efficient to convert to JSON on the server side. JSON.parse is going to be a lot faster than PHP.js's unserialize.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With