Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何解析Wordpress中的XML文件以用于其他CMS?_Php_Xml_Wordpress_Parsing_Modx - Fatal编程技术网

Php 如何解析Wordpress中的XML文件以用于其他CMS?

Php 如何解析Wordpress中的XML文件以用于其他CMS?,php,xml,wordpress,parsing,modx,Php,Xml,Wordpress,Parsing,Modx,我发现做这件事的资源很少。我正在使用MODX作为一个CMS,我想从Wordpress获取我现有的博客,并在新的CMS中使用它们。从MODX到WP的资源非常丰富,但是WP到MODX只有一种公开的方法,不幸的是,这种方法已经不起作用了。这是因为文章没有更新,还是WP的XML文件不兼容 不管怎样,我现在只能尝试用老式的方式来做这件事,我将无法把每一篇文章一篇一篇地看一遍。我想学习如何从WP获取导出的XML文件并将其解析为MODX,可能使用PHP。但我不知道从哪里开始 任何建议都会有帮助……是的,我已经

我发现做这件事的资源很少。我正在使用MODX作为一个CMS,我想从Wordpress获取我现有的博客,并在新的CMS中使用它们。从MODX到WP的资源非常丰富,但是WP到MODX只有一种公开的方法,不幸的是,这种方法已经不起作用了。这是因为文章没有更新,还是WP的XML文件不兼容

不管怎样,我现在只能尝试用老式的方式来做这件事,我将无法把每一篇文章一篇一篇地看一遍。我想学习如何从WP获取导出的XML文件并将其解析为MODX,可能使用PHP。但我不知道从哪里开始

任何建议都会有帮助……是的,我已经试过谷歌了。我不知道该从什么开始

谢谢

这里的代码片段可能对您有所帮助。您可以获取它的代码,修改一点并处理WP提要项,如下所示:

if (!empty($url) && $modx->getService('rss', 'xmlrss.modRSSParser')) {
    $rss = $modx->rss->parse($url);
    if (!empty($rss) && isset($rss->items)) {
        while (list($itemKey, $item) = each($rss->items)) {
            foreach ($item as $k => $v) {
                $item[$k] = str_replace(array('[',']'),array('[',']'),$item[$k]);
            }
            /// process rss items here  
            // f.e. add new modx resources
            $newArticle = $this->modx->newObject('modResource'); //new article
            $newArticle->set( 'template', ARTICLE_TEMPLATE_ID ); // replace ARTICLE_TEMPLATE_ID with actual article template id
            $newArticle->set( 'pagetitle', $item['title'] ); // pagetitle
            $newArticle->set( 'parent', ARTICLE_CONTAINTER_ID);
            $newArticle->set( 'content', $item['description'] );

            //add other valuable fields

            if(!$newArticle->save()){
                // modx error
            }

    }
}