How can PHP be used to display data extracted from an external page on a website?

To display data extracted from an external page on a website using PHP, you can use the cURL library to fetch the external page's content and then parse the desired data using HTML DOM parsing techniques. Once the data is extracted, you can display it on your website using PHP.

<?php
// URL of the external page
$url = 'https://www.externalpage.com';

// Initialize cURL session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute cURL session
$response = curl_exec($ch);

// Close cURL session
curl_close($ch);

// Parse the HTML content to extract desired data
$doc = new DOMDocument();
$doc->loadHTML($response);

// Find and display specific data from the external page
$elements = $doc->getElementsByTagName('h1');
foreach ($elements as $element) {
    echo $element->nodeValue;
}
?>