开发者

Using simple html dom

开发者 https://www.devze.com 2023-03-10 05:08 出处:网络
hi Using this code with simplehtmldom script (http://simplehtmldom.sourceforge.net/manual.htm): I got some error with it:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消