I would like to load a HTML document and modify it's text in PHP. For example, if I have a document like this:
<html>
<head><title>Test - Example.com</title></head>
<body>
<p><a href="http://www.example.com">Link number 1: Example.com</a></p>
<p>Link number 2: Example.com - some random text</p>
</body>
</html>
I would like to add an active link () to the second paragraph. But I don't want to touch other places where the Example.com string occurs, like the first paragraph or the title of the document. So I cannot use regular expressions for this, as I need to take into account the structure of the document. Any ideas as to how to tackle this problem? Also the HTML documents I will be receiving might be live webpages, so they might contain errors, JavaScript code, etc.