How can relative links on included external pages be converted to absolute links in PHP?

Relative links on included external pages can be converted to absolute links in PHP by using the `parse_url()` function to extract the base URL of the external page and then appending the relative links to this base URL to create absolute links.

// Get the base URL of the external page
$base_url = 'https://www.example.com'; // Replace this with the actual base URL

// Include the external page content
$external_page_content = file_get_contents('external_page.html'); // Replace this with the actual external page URL or file path

// Convert relative links to absolute links
$absolute_page_content = preg_replace('/(href|src)=[\'"]\//', '$1="' . $base_url . '/', $external_page_content);

// Output the page content with absolute links
echo $absolute_page_content;