2010-10-05 69 views
2

我在PHP下面的代碼與捲曲/ PHP提取HTML數據

$ch = curl_init("http://blog.com"); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch);  
curl_close($ch); 
echo $output; 

我試圖導入的代碼塊中<div id="content"></div>之間我想知道提取該代碼的最佳方式。

+0

請參閱http://stackoverflow.com/questions/3650125/how-to-parse-html-with-php – deceze 2010-10-05 05:46:04

+0

也http://stackoverflow.com/questions/3577641/best-methods-to-parse-html – 2010-10-05 05:46:44

回答

1

使用curl,在$輸出將使用它是一個字符串,因此創建一個DOM:

$html = str_get_html($content);

比,獲取內容:

$content = $html->find('#content');