<html>
<head>
<meta name="keywords" content="KEYWORDS">
<meta name="description" content="THIS TEXT">
</head>
我使用这个PHP代码:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$tags = $doc->getElementsByTagName('meta');
foreach ($tags as $tag) {
echo $tag->getAttribute('content');
}
但是代码只找到了atributte内容的首次出现, 但我需要第二个外观atributte内容......
答案 0 :(得分:0)
请试试这个
$dom = new DOMDocument();
$dom->loadHTML($html);
$elements = $dom->getElementsByTagName('meta');
foreach ($elements as $child) {
echo $child->nodeValue;
}
答案 1 :(得分:0)
做这样的事情:
<?php
$nodes = $xml->getElementsByTagName ("meta");
$nodeListLength = $nodes->length;
for ($i = 0; $i < $nodeListLength; $i ++)
{
$node = $nodes->item($i)->getAttribute('content');
}
?>