What are some common methods for extracting values from HTML elements in PHP?

When working with HTML elements in PHP, you may need to extract specific values from these elements, such as text content or attribute values. Common methods for extracting values from HTML elements in PHP include using DOMDocument, SimpleXMLElement, regular expressions, or third-party libraries like Symfony DomCrawler.

// Using DOMDocument to extract text content from a specific HTML element
$html = '<div><p>Hello, World!</p></div>';
$doc = new DOMDocument();
$doc->loadHTML($html);
$element = $doc->getElementsByTagName('p')->item(0);
$textContent = $element->textContent;
echo $textContent;