I need to load a HTML (maybe with DOMDocument loadHTML) and then replace all words A with word B but nothing inside an html tag.
This means that in the following html if we need to replace the word ‘test’ with ‘TEST’ it will only replace the text ‘this is a test’ with ‘this is a TEST’ and will keep intact the id=”test”
<html>
<head></head>
<body>
<div id="test"> this is a test </div>
</body>
</html>
Can’t get enough of DOMDocument 🙂
Not sure if there’s any performance loss to always doing a replace on
nodeValue; otherwise, replace the loop contents with: