Wiki Words

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hello everyone,

I'd like to know
how it is possible to parse a text
in order to find words matching
keywords included in a database.

I.e. like in a wiki site:

Everytime a keyword is found in the text
the page automatically inserts a link
to the keyword's page.

Thank you,


Re: Wiki Words

Several methods, all work, some are more efficient:

You could try str_replace() when displaying the content
( ) 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.


Re: Wiki Words

That's a great solution!

I had not considered that
parsing could be performed
when inserting or updating the text.

Thank you very much!


Site Timeline