2015-04-06 31 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