PHP Code:
<?php
$text //this is your input text
$keywords //this should have been retrieved some the DB as the keywords, numerically ($keywords[0], [1], ... etc.)
$responses //same, but for responses
foreach ($keywords as $keyword) {
if (strpos($text,$keyword)) {
$matches[$matchn] = $responses[$n];
$matchn++;
}
$n++;
}
print_r($matches); //prints the array of matches
//do a foreach loop with echo or whatever you'd like instead
?>
One alternative is to search for ' '.$keyword.' ' instead, so you know there are spaces on either side of the word. Then you get into the complexities of things like "keyword.", etc.
As it is now, though, if a keyword is car, then both racecar and car will return true for that.
An easy option (though might run into problems if you do complex things later) is to use:
$text = str_replace('.','',$text);
for each character that isn't relevant. Since "." will just be at the end of a search and probably get in the way for finding matches, getting rid of it (and ";" "," etc) will be a good idea.
Then just use ' '.$keyword.' ' as the search term above, meaning search for [space]keyword[space] within the text.
And... well....
else { echo 'try again'; }
you'd just need to setup an appropriate if statement, such as if (isset$matches)).
Bookmarks