使用 xpath 获取元描述标记
我需要内容描述和关键字标签内容。我有这个代码,但不要写任何东西。想法?
$str = <<< EOD
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="text in the description tag" />
<meta name="keywords" content="text, in, the, keywords, tag" />
</head>
EOD;
$dom = new DOMDocument();
$dom->loadHTML($str);
$xpath = new DOMXPath($dom);
$nodes = $xpath->query('/html/head/meta[name="description"]');
foreach($nodes as $node){
print $node->nodeValue;
}