我试图用php dom获取div内的值,我用下面的代码得到了值,但我没有得到它的php标签。 php dom不解释标签,我知道php dom不应该解释标签,但是还有解决标签的工作吗?
$selected_div = "wrapper";
$file = 'http://localhost/jugni/selected.php'; // $file contents = <html><body><div id = "wrapper"><?php echo "hello world"; ?></div></body></html>
$file_get= file_get_contents($file);
$doc = new DomDocument("1.0", "utf-8");
$doc->loadHTML($file_get);
$element = $doc->getElementById($selected_div);
$existing_Data = $element->firstChild->nodeValue;
echo $existing_Data;
//echo $existing_Data gives me - hello world - , but what I want is the php tags with it as well , eg < ? php echo "hello world "; ?>
答案 0 :(得分:0)
当你使用$file_get= file_get_contents($file);
时,php已经在服务器端执行,只有它的输出存在于$ file_get中。那个原始的php不会出现在那里。