quocbao
06-02-2005, 08:43 AM
Is there a function like serialize (http://php.net/serialize) in php ? :)
|
||||
javascript "serialize"quocbao 06-02-2005, 08:43 AM Is there a function like serialize (http://php.net/serialize) in php ? :) jbot 06-02-2005, 10:06 AM there isn't one as far as I can tell. however, you could always use this WDDX method (http://academy.bhtafe.edu.au/hwiebell/Wddx_SDK/Code_Listings/Viewable_As_Text/Serialize_htm.html). also, JS is a weakly typed language, so can't really see the point. what you could do, though, is create a new array and add it to it, something like this: (serial=[]).push(variable); jbot 06-02-2005, 10:16 AM you could always use JSRS or XHR to communicate with PHP and use that to serialize/deserialize the data. that might be the best method. quocbao 06-02-2005, 03:59 PM Thanks guy , but using WDDX is not fully support in PHP (to my knowledge , it's only supported on Win32 OS , is it right ?) , i will try XHR Harry Armadillo 06-02-2005, 04:29 PM What exactly are you wanting to do with your data? (And what kind of data?) You might be able to adapt the script from this thread (http://www.codingforums.com/showthread.php?t=55746), which dumps arrays into javascript-source strings. Or this start to a serialize function (http://www.codingforums.com/showthread.php?p=315540#post315540). quocbao 06-03-2005, 04:14 AM I want to pass data between PHP and Js . Using XHR or JSCR is too large . So i intend to save the serialized string to cookie , and PHP will unserialize the cookie to get the data (i don't want to pass data in URL because , there will be limited , right :) ? ) Can you help me more plz ! quocbao 06-05-2005, 10:04 AM Another question : Did anyone write a function to unserialize PHP String to Javascript Variable ? jbot 06-06-2005, 09:30 AM Did anyone write a function to unserialize PHP String to Javascript Variable ? why don't you google and find out for yourself ... andot 06-19-2006, 07:44 PM Here (http://www.coolcode.cn/?p=171) is a best PHP serialize/unserialize implementation for javascript. It can serialize/unserialize N,b,i,d,s,U,r,R,a,O,C. It is included in PHPRPC (http://sourceforge.net/project/showfiles.php?group_id=163368) parris 06-16-2008, 09:15 PM I know this is an old thread, but I made a function to serialize a javascript array in a way php can unserialize it. function serializeArray(a) { var serializedString = ''; var arrayLength = 0; for(var aKey in a) { //key definition if(aKey * 1 == aKey) //is_numeric? { //integer keys look like i:key serializedString += 'i:' + aKey + ';'; } else { //string keys look like s:key_length:key; serializedString += 's:' + aKey.length + ':"' + aKey + '";'; } //value definition if(a[aKey] * 1 == a[aKey]) { //integer value look like i:value serializedString += 'i:' + a[aKey] + ';'; } else if(typeof(a[aKey]) == "string") { //string value look like s:key_length:value; serializedString += 's:' + a[aKey].length + ':"' + a[aKey] + '";'; } else if(a[aKey] instanceof Array) { serializedString += serializeArray(a[aKey]); } arrayLength++; } serializedString = 'a:' + arrayLength + ':{' + serializedString + '}'; return serializedString; } - Parris |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum