Solution:1
You can use cURL in PHP to fetch the contents of a webpage. Here’s a reusable function:
/**
* Fetch a web resource (HTML, XML, images, etc.) from a URL.
* Returns an array containing HTTP response headers and content.
*/
function get_web_page($url)
{
$options = [
CURLOPT_RETURNTRANSFER => true, // return web page as string
CURLOPT_HEADER => false, // exclude headers in output
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // custom user agent
CURLOPT_AUTOREFERER => true, // auto set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // connection timeout
CURLOPT_TIMEOUT => 120, // response timeout
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
];
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
$header = curl_getinfo($ch);
curl_close($ch);
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
Notes:
If assets like images or stylesheets use relative URLs (e.g., /image.jpg), you may need to rewrite them into absolute URLs (http://domain.com/image.jpg).
To extract just specific parts (likeor), you can use DOM parsing (DOMDocument, simplexml, or XPath) if the HTML is well-formed. Otherwise, regex can work for simpler tasks.
Most shared hosting environments already have cURL enabled.