By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,405 Members | 1,531 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,405 IT Pros & Developers. It's quick & easy.

Wiki Words

P: n/a
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,


Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
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.

Jul 17 '05 #2

P: n/a
That's a great solution!

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

Thank you very much!


Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.