这是 RSS 提要的一部分
<item>
<title>
<![CDATA[
Japan backs coronavirus drug; Moscow keeps lockdown: Live updates
]]>
</title>
<description>
<![CDATA[
<div><img src="https://www.aljazeera.com/mritems/Images/2020/5/9/b738bc043efb400296eff230bcfd444f_18.jpg" style="width: 100%;"><div>Over 275,000 have died worldwide while more than 1.3 million have recovered as countries weigh easing of lockdown rules.</div></div>
]]>
</description>
<link>
https://www.aljazeera.com/news/2020/05/japan-backs-coronavirus-drug-moscow-lockdown-live-updates-200508232257831.html
</link>
<guid isPermaLink="false">592c6747e057269acbb31f383c9c110d</guid>
<dc:creator>
<![CDATA[ AJENews ]]>
</dc:creator>
<pubDate>Sat, 09 May 2020 01:18:50 GMT</pubDate>
<media:content medium="image" url="https://www.aljazeera.com/mritems/Images/2020/5/9/b738bc043efb400296eff230bcfd444f_18.jpg"/>
</item>
这里通过 DOMDocument() 加载 rss 提要内容并定义数组以保存内容并使用 getElementsByTagName
<?php
$rss = new DOMDocument();
$rss->load('https://rss.app/feeds/7e40Pu6EiBz9ourE.xml');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
//'dcUri' => $rss->lookupNamespaceUri('dc'),
//'authors' => $node->getElementsByTagNameNS($item[dcUri], 'creator'),
//'cre' => $item[authors]->item(0)->nodeValue,
);
array_push($feed, $item);
}
在 mysql 数据库中存储数组内容的代码,我已成功保存(标题、des、日期)
智慧大石
慕娘9325324
随时随地看视频慕课网APP