WordPress.org

Ready to get started?Download WordPress

Forums

CSV Importer
Escaping quotation marks / serialized array (2 posts)

  1. maorb
    Member
    Posted 3 years ago #

    Hi,

    I wrote a script which parses html DOM and outputs one csv file for all html pages needed to be imported.
    Everything works fine, except issue I encounter with quotation marks.
    I looked at the example.csv fle and didn't manage how should I escape them.

    The problematic field I've got is a serialized array that should be saves as a custom field. It holds values for several input fields.
    The serialized array is being crreated via the serialize($arr);, and as you know it has a lot of quotation marks inside.

    When I look in the my csv file, I see the seiralized array something like this:
    a:6:{s:10:""_video_wmv"";s:11:""cookegg.wvx"";s:7:""YouTube"";s:15:""www.youtube.com"";s:8:""Facebook"";s:10:""www.fb.com"";s:4:""Flix"";s:12:""www.flix.com"";s:8:""duration"";s:0:"""";s:15:""shorter_excerpt"";s:0:"""";}"

    But when I look in the database, I see it like this -
    s:196:"a:6:{s:10:"_video_wmv";s:11:"cookegg.wvx";s:7:"YouTube";s:15:"www.youtube.com";s:8:"Facebook";s:10:"www.fb.com";s:4:"Flix";s:12:"www.flix.com";s:8:"duration";s:0:"";s:15:"shorter_excerpt";s:0:"";}";

    meaning, a s:196:" has been added to the beginning of it, and a "; added to the end.
    This causes the WP not to interpret the data as needed to the appropriate fields.

    I don't even know if is an issue of escaping quotation marks, rather than have the serialized array be saved in the db as it is, without adding it these prefix and suffix.

    Any idea how can I deal with that?

    Many thanks,
    Maor

    http://wordpress.org/extend/plugins/csv-importer/

  2. maorb
    Member
    Posted 3 years ago #

    Ok, I found what is causing the problem, and this is bug in WordPress.

    You use the add_post_meta() to create the custom field. This function uses the add_metadata() function, whic uses the maybe_serialize() function.
    Well, the maybe_srialize() function should check if there is need to serialize or not, and perform serialization according that.
    But, it appears that the maybe_serialize() function always serialize and not only if needed.

    You can see it on wp-includes/functions.php, line 1005.

    This is why if you pass a serialized array/object it is serializing it again, and thus the prefix of the s:196 is appending.

    When I changed the core function maybe_serialize(), it all went ok!

    I've submited a ticket on the trac about this, if someone interested in following this -
    http://core.trac.wordpress.org/ticket/16597

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic