File Get Contents the Best Method
function fetchWebPage($url) { // Load the web page content $content = file_get_contents($url); // Check if the content is successfully loaded if ($content === false) { // If the web page doesn't exist, load a local file for error $content = file_get_contents('local_error_file.html'); } else { // Get the base URL $base_url = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST);