说这是HTML?
<html>
<body>
<embed scr="...." attr="..."></embed>
</body>
</html>
我想匹配整个嵌入代码<embed scr="...." attr="..."></embed>
。我怎么能这样做?
我到目前为止
$fragment = new DOMDocument();
$fragment->loadHTML($string);
$xp = new DOMXPath($fragment);
$result = $xp->query("//embed");
print_r($result->item(0));
答案 0 :(得分:7)
像这样:
<?php
$fragment = new DOMDocument();
$fragment->loadHTML($string);
foreach ($fragment->getElementsByTagName("embed") as $element)
{
echo $fragment->saveXML($element);
}
?>
答案 1 :(得分:2)