1

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 file_get_contents in this script. Anyone have an idea how to inser curl in this script?

3
  • We need some more information. Do you have your actual file? There is more than 1 simple html dom script. Commented Jun 4, 2011 at 21:17
  • Warning: file_get_contents(example.com/new/id_123.html) failed to open stream: HTTP request failed! in /var/www/vhosts/domain/httpdocs/simple_html_dom.php on line 40 where line 40 is $dom->load(call_user_func_array('file_get_contents', $args), true); Commented Jun 4, 2011 at 21:48
  • You can download the version with CURL from webarto.com/82/php-simple-html-dom-curl Commented Jul 13, 2011 at 12:50

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0
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);

2 Comments

oh thnx but how to integrate this with simplehtmldom?
@goni all above is php code, gives you data as string, try string functions and we can break it.
0

Please look at the examples under the PHP curl manual:

https://www.php.net/manual/en/function.curl-init.php

Unlike many manuals, the PHP manual is actually extremely helpful.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.