2010-10-05 67 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');