I'm trying to match words in a sentence to entries in a dictionary database, so that words in the sentence that match a word in the dictionary are turned into links. This means matching words in the sentence that are plural, or past tense to words in the dictionary that are not plural or past tense as well as dealing with words that are immediately followed by a comma or period.
Suppose I have the following sentence:
The planets revolve around the sun primarily in the plane of the solar system, as seen in the planetarium demonstration.
where I have planet, plane and planetarium in the database.
entry1=planet;
entry2=plane;
entry3=planetarium;
I want a script that does the following;
for($i=0;$i=$end_of_sentence;$i++){
for($j=0;$j=$num_words_in_dictionary,$j++){
if ($word_in_sentence[$i] == $entry[$j]){
$word_in_sentence[$i] =
'<a href="link_to_definition">'.$word_in_sentence.'</a>';
}
}
I've been splitting the sentence on spaces and looping through the sentence one word at a time. I've tried various forms of if(eregi( )), but I always end up matching plane, i.e., <a href="..">plane</a>t, or <a href="..">plane</a>tarium, but i can't seem to match planet or planetarium. If I go with
if($word_in_sentence == $entry) I don't know how to deal with plurals, past tense, commas or periods or whatever on the end of the word. Can someone give me a push in the right direction?
Thanks
B