public function parse_content_from_xml_string($xml_string) { libxml_use_internal_errors(true); $parser2 = __DIR__ . DIRECTORY_SEPARATOR . 'lib/QueryPath/QueryPath.php'; require_once $parser2; $parser2 = __DIR__ . DIRECTORY_SEPARATOR . 'lib/QueryPath/qp.php'; require_once $parser2; $content_items = array(); $items = qp($xml_string, 'item'); if (count($items) == 0) { $items = qp($xml_string, 'item'); } foreach ($items as $item) { $content_item = array(); //$arr = $item->eq(0)->contents(); // print $item->text(); // $el = qp($item, 'channel>item>title'); $el = $item->find('title'); $content_item['title'] = $el->eq(0)->text(); // $el = qp($item, 'channel>item>encoded'); //$el = $item->find('encoded'); $content_item['content'] = false; if ($content_item['content'] == false) { $el = $item->find('content'); $content_item['content'] = $el->eq(0)->text(); $content_item['content'] = $el->eq(0)->text(); } $content_item['created_at'] = false; if ($content_item['created_at'] == false) { $el = $item->find('post_date_gmt'); $content_item['created_at'] = $el->eq(0)->text(); } if ($content_item['created_at'] == false) { $el = $item->find('post_date'); $content_item['created_at'] = $el->eq(0)->text(); } if ($content_item['created_at'] == false) { $el = $item->find('pubDate'); $content_item['created_at'] = $el->eq(0)->text(); } if ($content_item['created_at'] != false) { $content_item['updated_at'] = $content_item['created_at']; } //$el = qp($item, 'channel>item>description'); $el = $item->find('description'); $content_item['description'] = $el->eq(0)->text(); if ($content_item['content'] == false) { $content_item['content'] = $c = $item->find('content')->eq(0)->innerHTML(); } if ($content_item['content'] == false) { $el = $item->find('summary'); $content_item['content'] = $el->eq(0)->text(); } if ($content_item['content'] == false) { $el = $item->find('encoded'); $content_item['content'] = $el->eq(0)->text(); } //$c= ($item->find('content')->text()); //$itm = $item->eq(0)->html(); // print $item->tag() . PHP_EOL; //$el = qp($item, 'channel>item>post_type'); $el = $item->find('post_type'); $content_item['post_type'] = $el->eq(0)->text(); $cats = $item->find('category'); // $cats = qp($item, 'channel>item>category'); foreach ($cats as $cat) { $content_item['categories'][] = $cat->text(); } $content_items[] = $content_item; } return $content_items; }