What are some common techniques or libraries used in PHP for parsing and manipulating HTML source code?
When working with HTML source code in PHP, it is common to use libraries or techniques for parsing and manipulating the code. Some popular options include using the DOMDocument class for parsing HTML, using regular expressions to extract specific elements, and using libraries like Simple HTML DOM Parser for more advanced manipulation tasks.
// Example using DOMDocument to parse HTML source code
$html = '<html><body><h1>Hello, World!</h1></body></html>';
$doc = new DOMDocument();
$doc->loadHTML($html);
// Get the <h1> element text content
$h1 = $doc->getElementsByTagName('h1')[0];
echo $h1->textContent;