php parsing speed optimization

Posted by Arnaud on Stack Overflow See other posts from Stack Overflow or by Arnaud
Published on 2011-01-07T13:29:34Z Indexed on 2011/01/07 13:53 UTC
Read the original article Hit count: 274

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about php

Related posts about parsing