|
Posted by ECRIA Public Mail Buffer on 05/26/05 11:12
Several methods, all work, some are more efficient:
You could try str_replace() when displaying the content
(http://us4.php.net/str_replace) but this would result in a significant
processing overhead (the function is not that efficient to begin with and
you would have to call it for every word - bad news)
This is what I would do:
1. I would assume that many more reads will be made than edits.
2. When inserting or updating text, I would compare each undefined or
'unlinked' word against 1) an ignore list and 2) a dictionary of defined
terms, and if there was a match, I would add a link to the inserted text.
3. I would keep a list of new definitions
4. When reading text, I <may> search for words against the new definitions
and replace them with links
5. Periodically - say daily, I would run a cron job that would match all
words in old entries against the new list and replace them with links (if
found), thereafter removing the words from the new definitions list and put
them a definition archive.
6. Rarely, but periodically (say monthly) I would run a check on all entries
against all definitions to ensure that all entries fully match definitions
when present. Depending on the exact code, this may not be necessary.
This is a crude algorithm but it should suffice for efficiency and it works.
There may be more elegant solutions.
ECRIA
http://www.ecria.com
[Back to original message]
|