Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: [JAVASCRIPT] Javascript Serialize

  1. #1
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [JAVASCRIPT] Javascript Serialize

    1) CODE TITLE: Javascript serializer

    2) AUTHOR NAME/NOTES: Shachi Bista

    3) DESCRIPTION: Serializes any string like the traditional PHP serialize function

    4) URL TO CODE:

    or, ATTACHED BELOW (see #3 in guidelines below):

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I'm not quite sure I understand... What exactly does it do?
    - Mike

  3. #3
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You would if you used the php serialize() function. Anyways it converts any plain text like this:

    Code:
    test
    array(1,2,"b");
    to:
    Code:
    s:4:"test"
    a:3{i:0;i:1;i:1;i:2;i:3;i:"b"}
    If you still don't get it then I suggest you to download the zip and check the html file. Even PHP sessions are in these formats.

    Hope it helps.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Under SpiderMonkey:
    Code:
    jserialize.js:10: SyntaxError: final is a reserved identifier:
    jserialize.js:10:               final = "a:"+item.length+":{";
    jserialize.js:10: ................^
    Changing this, it doesn't produce the same output as PHP serialize(). Compare:
    Code:
    twey@peordh ~/Documents/ddstuff $ js -f jserialize.js -f -
    js> var a = [];
    
    js> a.push(a);
    1
    js> serialize(a);
    a:1:{i:0;a:1:{i:0;a:;}}
    Code:
    twey@peordh ~/Documents/ddstuff $ php
    <?php
      $a = array();
      array_push($a, $a);
      print serialize($a);
    ?>
    a:1:{i:0;a:0:{}}
    Last edited by Twey; 01-07-2007 at 04:34 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Twey: Haven't tested it in all browsers. I never knew that even final was a reserved word. Too bad. Do you think changing that varname will fix the error?

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It does. However, the difference in output remains.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    It does. However, the difference in output remains.
    How come??

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Sorry, I modified my above post, apparently after you read it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Umm yeah... Well. I have a question, what does the "final" keyword signify?
    - Mike

  10. #10
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    mburt: I just have no idea.

    Twey: I've got to fix that too, that goes into my TODO list, Thank you for pointing that out Twey. If I am lucky enough I'll certainly fix it.

    There still are a lot of bugs that needs to be fixed. This is just an experimental script I created for AJAX to transfer and convert js arrays so that PHP can interpret them.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •