I'm trying to write an article checker that receives content from a form and highlights words if they match those in an array created from a textfile (which happens to be the top 1000 most used words in English, one per line).
The array's being created ok, but the str_ireplace which is run as the foreach loop moves through the wordlist array doesn't highlight any matches it finds.
/* Get the form contents */
$article = stripslashes ( $_POST [ 'article' ] );
/* Create array from word list (list from http://www.giwersworld.org/computers/linux/common-words.phtml) */
$wordlist = array_map ( 'rtrim', file ( 'wordlist.txt' ) );
/* Check each word in the list against the article */
foreach ( $wordlist as $word ) {
str_ireplace ( $word, '<strong>'.$word.'</strong>', $article );
}
/* Print results */
echo $article;
Can anyone help me with this?