我有一个 PHP 文件,我想用div
id
.
这里的代码:
<div id="vids" channelname="test">
<?php
load_video(1,$channelname); //channelname mays contains "test"
function load_video($start_index,$channelname)
{
...
}
?>
</div>
我想提取channelname
PHP 函数调用 ( load_video
) 之前的值来使用$channelname
。
我试过这个:
$doc = new DOMDocument();
$doc->load('test.php'); //Same result with loadHtml() and load HtmlFile()
$element = $doc->getElementById('vids');
$attr = $doc->getAttribute('channelname');
但它不起作用。
print_r($element); // No results
$element->getAttribute('channelname'); //Fatal error: Call to a member function getAttribute() on a non-object