How can PHP be used to extract data between specific HTML tags, such as <td> and </td>?
To extract data between specific HTML tags like <td> and </td> in PHP, you can use the DOMDocument class to parse the HTML content and then use XPath to query for the specific tags. By loading the HTML content into a DOMDocument object, you can easily navigate the DOM tree and extract the desired data between the specified tags.
$html = '<table><tr><td>Data 1</td><td>Data 2</td></tr></table>';
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$tdNodes = $xpath->query('//td');
foreach ($tdNodes as $td) {
echo $td->nodeValue . "\n";
}