Answers for "file_get_contents url fail"

PHP
0

file_get_contents url fail

New file_get_contents that checks valid urls

function get_contents_url($url, $u = false, $c = null, $o = null) {
        if (filter_var($url, FILTER_VALIDATE_URL)) {
            $headers = get_headers($url);
            $status = substr($headers[0], 9, 3);
            if ($status == '200') {
                return file_get_contents($url, $u, $c, $o);
            }
        }
        return false;
    }
Posted by: Guest on October-20-2021
0

file_get_contents url fail

New file_get_contents that checks valid urls

function get_contents_url($url, $u = false, $c = null, $o = null) {
        if (filter_var($url, FILTER_VALIDATE_URL)) {
            $headers = get_headers($url);
            $status = substr($headers[0], 9, 3);
            if ($status == '200') {
                return file_get_contents($url, $u, $c, $o);
            }
        }
        return false;
    }
Posted by: Guest on October-20-2021

Browse Popular Code Answers by Language