Thank you Drew, but unfortunately I am having the same problem as before. I have 1000 words in the table and want to search for each one. Your code, and the code I have included works great when the word to search for is manually coded like:
$words = array('fuck', 'shit', 'damn', 'ass');
I built a dynamic array from the query results, but no luck. $array printed out on the screen as "array('fuck', 'shit', 'damn', 'ass')", so I used the expression $words = $array;, which did not work either.
I also built an array with a key value, $counter, which didn't work as seen in the code below. If I use $array = array('shit', 'fuck', '420'); as also seen in this code, all three tests find the word. I don't understand why searching for a variable specified word doesn't work; it only works if the work being searched for is actually coded into the page. ??? Thanks again!
$thestring = "666 fuck shit cock 420";
$sql="
select word
from words
";
$result = mysql_query($sql) or die (mysql_error());
$counter = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$fword = strtolower($row['word']);
$array[$counter] = $fword;
$counter++;
}//end while
//$array = array('shit', 'fuck', '420');
foreach($array as $word)
{
if (preg_match('/' . preg_quote($word) . '/i', $thestring, $match))
{
echo 'bad word found! you can\'t say ' . $match[0] . '!!!!!!';
}
$test = strpos($thestring, $word);
{
if($test === false)
{
}
else
{
print "word was found with strpos - $word";
}
}
if(eregi($word, $thestring))
{
print "word found with eregi - $word";
}
exit;
}