Using simple html dom
hi Using this code with simplehtmldom script (http://simplehtmldom.sourceforge.net/manual.htm): I got some error with it:
failed to open stream: HTTP request failed!
I think should be use curl instead of fi开发者_运维问答le_get_contents in this script. Anyone have an idea how to inser curl in this script?
There is a simple_html_dom
version that already implement cURL instead file_get_contents
found here.
I use this version changing file_get_html
function in its ->load call like this:
$dom->load(getWithCurl($args[0]));
with getWithCurl
function taken from get remote HTML with cURL and PHP.
it works fine.
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = 'http://simplehtmldom.sourceforge.net/manual.htm';
echo $data = get_data($url);
Please look at the examples under the PHP curl manual:
http://us2.php.net/manual/en/function.curl-init.php
Unlike many manuals, the PHP manual is actually extremely helpful.
I did this in my CentOS
yum install php-mbstring
yum install php-xml
yum install php-xmlrpc
every thing worked after that with simple_html_dom class
精彩评论