我正在尝试显示此NVD XML文件的最新内容:
http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-recent.xml
我可以使用以下代码列出所有这些代码,但我只对显示最近的十个(从2013年开始)感兴趣,并且XML文件按时间顺序列出它们(从2011年开始)
<?php
$file= 'http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-recent.xml';
$xml = file_get_contents($file);
$sxe = new SimpleXMLElement($xml);
$ns = $sxe->getNamespaces(true);
echo "<b>Latest Vulnerabilities:</b><p>";
foreach($sxe->entry as $entry)
{
$vuln = $entry->children($ns['vuln']);
$href = $vuln->references->reference->attributes()->href;
echo "<a href=" . $href . ">" . $vuln->{'cve-id'} . "</a><br>";
}
?>
答案 0 :(得分:0)
由于您无法直接操作XML数组,因此类似的内容应该可以满足您的需求:
$file= 'http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-recent.xml';
$xml = file_get_contents($file);
$sxe = new SimpleXMLElement($xml);
$ns = $sxe->getNamespaces(true);
echo "<b>Latest Vulnerabilities:</b><p>";
$all = $sxe->entry;
$length = count($all);
$offset_start = $length - 10;
for($i = 0; $i < $length; $i++)
{
if($i >= $offset_start)
{
$entry = $all[$i];
$vuln = $entry->children($ns['vuln']);
$href = $vuln->references->reference->attributes()->href;
echo "<a href=" . $href . ">" . $vuln->{'cve-id'} . "</a><br>";
}
}