Accessing date as XML node in PHP [duplicate]

ぃ、小莉子 提交于 2019-12-08 14:46:32

The date is under the dc namespace which we can see points to http://purl.org/dc/elements/1.1/, so for example:

$streamData = simplexml_load_file('http://www.naps.org/index.php/rss/','SimpleXMLElement', LIBXML_NOCDATA);


foreach ($streamData->channel->item as $item)
{
    $dc = $item->children('http://purl.org/dc/elements/1.1/');

    $itemDate = date_parse($dc->date);
    $itemYear = $itemDate['year'];
    $itemMonth = $itemDate['month'];
    $itemDay = $itemDate['day'];

    $itemOutputDate = $itemYear.'-'.$itemMonth.'-'.$itemDay;

    echo $itemOutputDate;
}
$streamData->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/");
$nodes = $streamData->xpath("//item/dc:date");

If your data source is OK, then this works for me with simplexml:

(string) $item->date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!