How can PHP be used to extract data from HTML elements with specific IDs, such as "grandTotal" or "total_item_1"?

To extract data from HTML elements with specific IDs using PHP, you can use the PHP Simple HTML DOM Parser library. This library allows you to easily manipulate HTML elements and extract data based on their IDs. You can use the find() method to locate elements with specific IDs and then retrieve the data you need from those elements.

<?php
// Include the library
include('simple_html_dom.php');

// Load the HTML file
$html = file_get_html('example.html');

// Find the element with ID "grandTotal" and extract its data
$grandTotal = $html->find('#grandTotal', 0)->plaintext;

// Find the element with ID "total_item_1" and extract its data
$totalItem1 = $html->find('#total_item_1', 0)->plaintext;

// Output the extracted data
echo "Grand Total: $grandTotal";
echo "Total Item 1: $totalItem1";
?>