I have a database table for a glossary which contains a glossary_term field and a glossary_definition field. What I need my script to do is get all of the terms and definitions from the table and loop through and display them.
Whilst it is looping through and outputting the definitions it does another loop and checks to see if any of the terms are contained in the definition. If so it replaces the string with a link to this term.
The problem comes when there are terms that contain two or more words. For example if the first term is ‘added bonus’ and a definition was ‘Complimentary drinks are an added bonus’ the script would replace ‘added bonus` in the definition to ‘<a href=”glossary.php?term=added_bonus”>added bonus</a>’.
As the script loops through it comes across the term bonus, this is where the issue is. It then finds the word bonus in the definition so our previously changed link now becomes ‘<a href=”glossary.php?term=added_bonus”>added <a href=”glossary.php?term=bonus”>bonus</a></a>’
What I think I need to do is check to see if the string is contained within a link, e.g. when it looks for ‘bonus’ it looks to see if bonus is already part of a link.
I’m struggling with figuring out the best way to achieve this, does anyone have any other ideas or suggestions on my solution?
Thanks for any help