2015-04-06 33 views
-1

我想用php dom得到div里面的值,我用下面的代码得到了值,但是我没有得到它的php标签。 PHP DOM不解释标签,我知道PHP DOM不应该解释标签,但有没有解决标签的工作呢?php dom不解释php标签

$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

所以,实际上你希望在你的'$ file_get = file_get_contents($ file);'中有'<?php'和'?>'? – 2015-04-06 00:12:02

+0

@测试,是的,有没有办法解决这个问题,<? PHP和? > – Manu 2015-04-06 00:27:33

回答

0

到时候你使用$file_get= file_get_contents($file);的PHP已经在服务器端执行,只有它的输出出现在$ file_get。原始的php不会出现在这一点上。

+0

好的,那么你有什么建议约翰? – Manu 2015-04-06 00:28:30

+0

我建议重新考虑为什么你需要找到php标签。请解释你正在寻找的最终结果,你想完成什么? – 2015-04-06 00:31:24

+0

它只是不是PHP标签,它不显示任何标签,例如。如果我有一个< h1 >标签里面的div,它不会显示,要么我需要做到这一点..请lemme知道如果有一种方式 – Manu 2015-04-06 00:35:29