Transfer 404 file to fpf but view in browser

If you go to this page in a browser: http://www.x-rates.com/d/TRY/table.html , you can see that it works fine, but when I try to do $doc = new DOMDocument(); $doc->loadHTMLFile('http://www.x-rates.com/d/TRY/table.html'); $doc = new DOMDocument(); $doc->loadHTMLFile('http://www.x-rates.com/d/TRY/table.html'); it returns 404. I also tried to do file_get_contents() and send the html to the DOMDocument this way, but no luck. Any help gratefully received.

0
php
source share
2 answers

404 looks like the standard response code you provided for the URL:

 $ curl -I http://www.x-rates.com/d/TRY/table.html HTTP/1.1 404 Not Found Date: Mon, 01 Aug 2011 12:23:49 GMT Server: Apache/2.2.19 Content-Type: text/html 

You can get the body of the HTTP response and load it with DomDocument as a string.

This can be done by using file_get_contents Docs and setting the ignore_errors HTTP context parameter . Code example:

 $url = 'http://www.x-rates.com/d/TRY/table.html'; // Create a stream $opts = array( 'http'=>array( 'ignore_errors'=> true, ) ); $context = stream_context_create($opts); // Open the file using the HTTP headers set above $file = file_get_contents($url, false, $context); $doc = new DOMDocument(); $doc->loadHTML($file); 
+4
source share

The page returns 404, and I believe that it does this intentionally in order to complicate it. I found this on my website:

Retrieving data using tools such as PHP, LWP, Java, and Microsoft, for example, is not allowed.

You might want to double check that you are actually allowed to do what you are doing, I am concerned that you are infringing copyright.

0
source share

All Articles