0

我有一个 PHP 文件,我想用div id.

这里的代码:

<div id="vids" channelname="test">
<?php
 load_video(1,$channelname); //channelname mays contains "test"
 function load_video($start_index,$channelname)
 {
  ...
 }
 ?>
</div>

我想提取channelnamePHP 函数调用 ( 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
4

1 回答 1

0

尝试这个:

ob_start();
include 'test.php';
$strResult = ob_get_clean();

$doc = new DOMDocument();
$doc->loadHTML($strResult); //Same result with loadHtml() and load HtmlFile()
$element = $doc->getElementById('vids');
$attr = $element->getAttribute('channelname');
于 2014-01-11T18:55:33.210 回答