I want to download the contents of a URL using PHP, even if the HTTP response code is 404. file_get_contents will error out, and I wasn't able to find an answer using Google. How can I do this?
I want to download the contents of a URL using PHP, even if the HTTP response code is 404. file_get_contents will error out, and I wasn't able to find an answer using Google. How can I do this?
Step 1: check the return code:
$content = file_get_contents("websitelink");
if($content === FALSE) { // handle error here... }
Step 2: suppress the warning by putting an error control operator (i.e. @) in front of the call to file_get_contents(): $content = @file_get_contents($site);