You can use DOM+Xpath to fetch and change the text nodes inside an HTML document:
$html = <<<'HTML'
<html>
<body>
<h1>Hello World!</h1>
<div>
<p>Lorem Ipsum...</p>
</div>
</body>
</html>
HTML;
$dom = new DOMDocument();
$dom->loadHtml($html);
$xpath = new DOMXPath($dom);
$nodes = $xpath->evaluate("//text()");
foreach ($nodes as $node) {
$node->nodeValue = strToUpper($node->nodeValue);
}
echo $dom->saveHtml();