2014-03-05 14 views
1

我目前正在運行Windows 7WAMP已安裝。如何在Windows上使用WAMP運行PHP簡單HTML DOM解析器?

我試圖安裝PHP簡單的HTML DOM解析器http://simplehtmldom.sourceforge.net/)來運行下面的代碼。

我收到一條致命錯誤消息。這可能是因爲DOM解析器沒有安裝或位置不正確。

如何安裝解析器?我是否簡單地將它複製到WAMP文件夾中,還是從一個PHP文件中調用它?

錯誤:

Fatal error: Call to undefined function file_get_html() in  
C:\wamp\www\PHP_SCRAPER\_jobs\jobs_dom.php on line 4 

<?php 

代碼:

// Create DOM from URL or file 
$html = file_get_html('http://www.google.com'); 

// Find all images 
foreach($html->find('img') as $element) 
     echo $element->src . '<br>'; 

// Find all links 
foreach($html->find('a') as $element) 
     echo $element->href . '<br>'; 

?>  

回答

6
<?php 

// Include the php dom parser  
include_once 'path_to_php_dom_parser.php'; 

// Create DOM from URL or file 

$html = file_get_html('http://www.google.com'); 

// Find all images 
foreach($html->find('img') as $element) 
     echo $element->src . '<br>'; 

// Find all links 
foreach($html->find('a') as $element) 
     echo $element->href . '<br>'; 

?> 

您需要包括從你它存儲在服務器上的位置解析器腳本

相關問題