$html = '<html><body><span class="text">Hello, World!</span></body></html>';
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$span = $xpath->query("//span[@class='text']")->item(0);
echo $span->textContent;
Outputs:
Hello, World!