Click to See Complete Forum and Search --> : Eregi,Arrays, and IF Statements


brendandonhue
08-20-2003, 10:55 AM
I have an if/else along the lines of
if(eregi("word1",$line)||eregi("word2",$line)||eregi("word3",$line)....etc
But it has hundreds and hundreds of eregis.

If I put all the words into an array, how can I do an eregi on the array instead of doing one for every single word? This would be much easier for me to maintain, as I could just keep a text file containing all the words and use file() to make it into an array.
I also have MySQL if needed, although I would prefer to do this flatfile.

Hope someone understood that-if you did, thanks in advance :)

Kr|Z
08-20-2003, 11:25 AM
I dont know if there is any better ways, but you could use a loop:


$words = file();

foreach($words as $word) {
if(eregi($word, $line)) {
$ok = TRUE;
break;
}
}

if($ok) {
print("True");
}

brendandonhue
08-21-2003, 11:49 AM
Thanks, I got it using something like that.