I then have another array which contains words from a file. I'm using
Code: Select all
fileMy code is as follows:
Code: Select all
$file = file("banned.txt");
$input = "the only word not allowed in this string is banned";
$input = explode(" ", $input);
for ($i = 0; $i < count($file); $i++) {
for ($j = 0; $j < count($input); $j++) {
if ($file[$i] == $input[$j]) {
echo $file[$i], " matches ", $input[$j], "\n";
}
else {
echo $file[$i], " doesn't match ", $input[$j], "\n";
}
}
}The output from this script is:banned
words
As you can see, 'banned' also contains a newline character which is causing it not to match with the word from the string.banned
doesn't match the
banned
doesn't match only
banned
doesn't match word
banned
doesn't match not
banned
doesn't match allowed
banned
doesn't match in
banned
doesn't match this
banned
doesn't match string
banned
doesn't match is
banned
doesn't match banned
words doesn't match the
words doesn't match only
words doesn't match word
words doesn't match not
words doesn't match allowed
words doesn't match in
words doesn't match this
words doesn't match string
words doesn't match is
words doesn't match banned