Hi,
I'm making a chat script, and as part of it, I'm adding a "bad word" filter that identifies bad words during registration.
The bad words are contained in a flat text file, one on each line, and I've been using the file() function to get the words into an array and the foreach() function to evaluate them all. Trouble is, my array ends up coming out as "arrayarray...(continued)" and nothing else.
This is my code:
$badwords_file = file("badwords.txt");
foreach($badwords_file as $badword)
{
$check = strpos($_POST['username'], $badword);
if($check === 0)
{
$unacceptable_name = '1';
}
if($check)
{
$unacceptable_name = '1';
}
}
if($unacceptable_name == TRUE)
{
echo '<meta http-equiv="refresh" content=0;url=index.php?alert=That+username+is+unacceptable.>';
}
else {
[REST OF MY REGISTRATION CODE]
}
I'm using the strpos function to check if each badword exists in the username that the user has submitted, and if it does, it is supposed to assign a "true" value to the $unacceptable_name variable. I added the if($check === 0) bit because its possible that the badword exists at position 0 and therefore otherwise it would evaluate to false, which would be wrong.
I just can't figure out the problem - when I try to test what's going wrong by adding "echo $badword" to the foreach loop, all that gets returned is a load of "ArrayArrayArray"... stuff.