I would like to add tooltip or generate link according to the element available in the database, for exemple if the html page printed is:
to reboot your linux host in single-user mode you can …
I will use explode(” “, $row[page]) and the idea is now to lookup for every single word in the page to find out if they have a related referance in this exemple let’s say i’ve got a table referance an one entry for reboot and one for linux
reboot: restart a computeur
linux: operating system
now my output will look like (replaced < and > by @)
to @a href=”ref/reboot”@reboot@/a@ your @a href=”ref/linux”@linux@/a@ host in single-user mode you can …
- Instead of have a static list generated when I saved the content, if I add more keyword in the future, then the text will become more interactive.
My main concerne and question is how can I create a efficient enough process to do it ?
- Should I store all the db entry in an array and compare them ?
- Do an sql query for each word (seems to be crazy)
- Dump the table in a file and use a very long regex or a “grep -f pattern data” way of doing it?
- Or or or or I’m sure it must be a better way of doing it, just don’t have a clue about it, or maybe this will be far too resource un-friendly and I should avoid doing such things.
Cheers!
depending on the amount of keywords in the db there are two solutions.
1. if amount of keywords is less then amount of words in the text. Then you just pull all the keywords from db and compare them.
2. if amount of keywords is more then words in text. Dynamically create a single query which will bring all necessary words. eg. SELECT * FROM keywords WHERE keyword=’system’ OR keyword=’linux’ etc.
However if you are really concerned about resources i would suggest you to create a caching system. you process each page once, then store both original text and result in the db. if keyword table is updated you can reprocess all the pages once again.