How can HTML blocks be extracted using SimpleXML in PHP?

To extract HTML blocks using SimpleXML in PHP, you can load the HTML content into a SimpleXMLElement object and then use XPath to query and extract specific elements or blocks from the HTML structure.

// Load HTML content into SimpleXMLElement
$html = '<div><p>Hello World!</p><p>This is a test</p></div>';
$xml = new SimpleXMLElement($html);

// Use XPath to extract specific HTML blocks
$blocks = $xml->xpath('//p');

// Output extracted blocks
foreach ($blocks as $block) {
    echo $block->asXML();
}