How can PHP be used to extract HTML source code?

To extract HTML source code using PHP, you can use the file_get_contents() function to retrieve the HTML content from a URL or a local file. You can then use this content for further processing, such as parsing or extracting specific data.

// URL of the webpage you want to extract HTML source code from
$url = 'https://www.example.com';

// Get the HTML source code from the URL
$html = file_get_contents($url);

// Output the HTML source code
echo $html;