Automatically creating links to a glossary entry?
Posted: Wed Apr 29, 2009 9:23 pm
I was thinking about how to add "glossary" links to website pages automatically for specific sequences of words. Like, say I want every occurrence of the phrase "expensive automobiles" on a website to automatically become a link to a glossary definition of that word (on another page), so on a page with this content:
it would automatically insert a link to a glossary entry around "expensive automobiles". (This is just an example.) In this way, if I later added a glossary entry for the phrase "good choice", every occurrence of that phrase could become a link automatically and I wouldn't have to go back and manually insert it everywhere that it occurred.
The way I thought of is to load the actual page content in a string variable and use preg_replace to find all occurrences of things that are in the glossary and replace them with a "linked" version, but I don't know if that would be efficient or a bad way to do it?
Code: Select all
<p>
For people who like to drive and are rich, expensive automobiles are a good choice.
</p>The way I thought of is to load the actual page content in a string variable and use preg_replace to find all occurrences of things that are in the glossary and replace them with a "linked" version, but I don't know if that would be efficient or a bad way to do it?