The most obvious way I can think of doing this is looping through every keyword from your database, and running a preg_replace
on your HTML for each (just replace each word with an appropriate hyperlink).
Your regular expression is likely to be complex, because you will need to make sure that none of the word replacements interfere with your HTML, and you will also want to make sure you only replace whole words and not partial words.
Lastly, if your word database is very large, this will be expensive to do on every request. So consider performing it once and storing the result.
Alternatively, offload the processing to the client and do the replacement with JavaScript. Modifying HTML tags may not be a problem then, because you should be able to run the replace on only the text nodes of the DOM. But again, if your database is large, you will have to send a long list of words to the client for the JavaScript to loop through.