PHP:
הורדת דף אינטרנט

איך לעשות:

<?php
$url = 'http://example.com';
$content = file_get_contents($url);
if ($content !== false) {
    // Do something with the content
    echo $content;
} else {
    // Handle the error
    echo "Couldn't download the page.";
}
?>

Sample Output:

<!doctype html>
<html>
<head>
    <title>Example Domain</title>
...
</head>
<body>
...
</body>
</html>

עיון מעמיק:

Back in the day, we had to use CURL for downloading web pages, which gave us more control but was verbose. Now, file_get_contents is a handy alternative for simple tasks. But remember, for complex tasks or error handling, CURL is still preferable. When using file_get_contents(), check for its return value, false, which indicates failure. To handle HTTP headers, timeouts, and other finer details, delve into stream_context_create().

ראה גם: