从XML导入将忽略序列化的自定义字段

时间:2013-02-25 作者:Oliver Whysall

我一直在尝试使用WordPress导入工具将一些内容导入到自定义字段中,但它似乎将数据库中的自定义字段留空。

<wp:meta_value><![CDATA[a:19:{s:7:"address";s:50:"52, St. Michaels Rd,Sheffield,S359YN";s:11:"gpsLatitude";s:18:"";s:12:"gpsLongitude";s:18:"";s:18:"streetViewLatitude";s:9:"";s:19:"streetViewLongitude";s:18:"";s:17:"streetViewHeading";s:17:"";s:15:"streetViewPitch";s:18:"";s:14:"streetViewZoom";s:1:"0";s:9:"telephone";s:13:"01142570288";s:5:"email";s:19:"";s:3:"web";s:17:"";s:11:"hoursMonday";s:9:"";s:12:"hoursTuesday";s:9:"";s:14:"hoursWednesday";s:9:"";s:13:"hoursThursday";s:9:"";s:11:"hoursFriday";s:9:"";s:13:"hoursSaturday";s:6:"";s:11:"hoursSunday";s:6:"";s:18:"alternativeContent";s:0:"";}]]></wp:meta_value>
这似乎没有什么大问题,但当我使用导入器工具时,它会忽略这一点,并在数据库中留下一个空白。

你知道发生了什么事,或者是否有明显的缺失?

1 个回复
最合适的回答,由SO网友:Oliver Whysall 整理而成

我最近从一位朋友那里学到了序列化数组,现在一切都有了意义!在解决了这个问题后,它最终在导入方面起到了作用。

以此为例:a:1:{s:7:"address";s:50:"52, St. Michaels Rd,Sheffield,S359YN";}

  • a:1: 这是数组大小,此数组中有一条信息为1

  • s:7:"address"; 这是值的大小。因此,对于address,单词address中有7个字符,因此值大小为7。

    大小:值

    还有如下所示的整数值:

    i:值

    • Bolean值如下所示:

      b:值;(不存储“true”或“false”,存储“1”或“0”)

这就是序列化数组中基本上需要担心的所有内容,更正后,wordpress导入器会将这些内容导入到数据库中,而不会出现任何问题,但如果这些内容错误,则会自动转义并将数据库行中的字段留空。

Examples:

String
 s:size:value;

 Integer
 i:value;

 Boolean
 b:value; (does not store "true" or "false", does store \'1\' or \'0\')

 Null
 N;

 Array
 a:size:{key definition;value definition;(repeated per element)}

 Object
 O:strlen(object name):object name:object size:{s:strlen(property name):property name:property definition;(repeated per property)}

 String values are always in double quotes
 Array keys are always integers or strings
    "null => \'value\'" equates to \'s:0:"";s:5:"value";\',
    "true => \'value\'" equates to \'i:1;s:5:"value";\',
    "false => \'value\'" equates to \'i:0;s:5:"value";\',
    "array(whatever the contents) => \'value\'" equates to an "illegal offset type" warning because you can\'t use an
    array as a key; however, if you use a variable containing an array as a key, it will equate to \'s:5:"Array";s:5:"value";\',
     and
    attempting to use an object as a key will result in the same behavior as using an array will.

结束

相关推荐

XML to Json code issue

我编写了一个脚本,以XML格式显示按类别组织的所有WordPress帖子。代码为// get all the categories from the database $cats = get_categories(); header(\'Content-type: text/xml\'); echo \'<categories>\'; // loop through the categries foreach ($cats as $cat) {