url_get_contents()

Fetch the contents of a URL and return it as a string. A simple way to pull a web page or file when you don't need headers or status codes.

Syntax

url_get_contents(url)

Parameters

Name Type Required Description
url string yes The URL to fetch.

Returns

The fetched content as a string. Throws on a fetch error.

Example

$html = url_get_contents("https://example.com/status.html");
$state = preg_match_gf('/status:\s*(\w+)/i', $html, 1);
sys_log("Remote status: " . $state);

Example output

"<html> ... </html>"

Notes

  • For control over method, headers, or to read the status code, use curl_request() instead.

See also: curl_get(), strip_tags_gf()