Welcome to WebmasterWorld Guest from 184.108.40.206
Not posted here for donkey's years! :o)
Anyway I have a query. What I am trying achieve is to do some on the fly linking. What I have is some content from a DB, and within the content if a particular word appears then I would like to insert a link to the product page.
Now I'm not quite sure the best way of implementing this. whether I should create a keywords table in the DB and then compare the content with the keywords table?
Any suggestions or examples of code?
Why not just modify the content in the database to include the link?
Because then it's harder to change them on the fly.
I presume it's a small set of links and words (like a few hundred at most)? Since you're going to need to get all the words into an array for every page, I would probably just store it in a CSV file, upload the words and the replacement link to an array, and then use preg_replace or str_replace, sending it the array of word, the array of replacement links and the text from the DB.
str_replace has the advantage of speed, but the disadvantage of not being able to distinguish whole words from strings within words.
I wasn't trying to say that this situation doesn't call for regular expressions, just that it's always best to evaluate the need before using them. :)