SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    php5 serialize problem

    I have some code that uses serialize to save array data to a MySQL database. It works great except that it blows up when the data contains doble quotes. Suppose a field has the word home

    it is serialized as

    s:4:"home"; (string four bytes long)

    but "home" (with quotes) is serialized as

    s:8:""home""; (string eight bytes long)

    but since it is only 6 bytes long, unserialize = failed

    I've tried html entities and add slashes and nothing works.

    magic_quotes_gpc are ON
    Denny Schlesinger
    web services

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    var_dump(serialize('"home"')); 
    should produce
    Code:
    string(13) "s:6:""home"";"
    Does it not?

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Turn magic_quotes off, its no good.
    The below works for me. o.o
    PHP Code:
    $arr = array( '"value"''another \'value\' nothing' );
    print_r$arr serialize$arr ) );
    print_runserialize$arr ) ); 
    Code:
    a:2:{i:0;s:7:""value"";i:1;s:23:"another 'value' nothing";}
    Array
    (
        [0] => "value"
        [1] => another 'value' nothing
    )
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •