因此,我一直在尝试将数据文件作为php变量来获取,但一直无法获取。这是来自源代码的。
<div class="videoplayer" id="video1" data-files="files.mp4">这是我使用最成功的代码,但是我没有得到数据文件的值。
<?php
$doc = new DOMDocument();
#$doc->loadHTML($url);
$doc->validateOnParse = true;
libxml_use_internal_errors(true);
$doc->loadHtml(file_get_contents($url));
libxml_use_internal_errors(false);
$classname="videoplayer";
$finder = new DomXPath($doc);
$result = $finder->query("//*[contains(@class, '$classname')]");
// There's actually something in the list
if($result->length > 0) {
$node = $result->item(0);
echo "{$node->nodeName} - {$node->nodeValue}";
}
else {
echo "Empty";
}
?>有什么办法可以做到这一点吗?
发布于 2018-01-26 16:37:00
您可以使用DOMElement::getAttribute获取属性的值。因此,要获取data-files属性,请使用:
$file = $node->getAttribute("data-files");
echo "$node->nodeName - $file";https://stackoverflow.com/questions/48457827
复制相似问题