Please see if this can help you:
Code: Select all
//Test 1: nothing from blacklist is found, so all checks are negative and the script will always continue.
$blacklist = "Seat,Fiat,Skoda";
$input = "My new car is an AUDI";
foreach($tkn, $blacklist, ",")
{
if ($tkn==""){break;}
if strpos($input,$tkn) == -1 )
{
msg "Test 1<crlf 2>Continue.<crlf>$tkn was NOT found in<crlf>$input.";
}else{
msg "Test 1<crlf 2>Skipped.<crlf>$tkn WAS found in<crlf>$input.";
}
}
Code: Select all
////////////////////////////////////////////////////////////////////////////////////
//Test 2: One from blacklist is found, so all checks but the last are negative, and the script will skip once.
$blacklist = "Seat,Fiat,Skoda";
$input = "My new car is an Skoda";
foreach($tkn, $blacklist, ",")
{
if ($tkn==""){break;}
if strpos($input,$tkn) == -1 )
{
msg "Test 2<crlf 2>Continue.<crlf>$tkn was NOT found in<crlf>$input.";
}else{
msg "Test 2<crlf 2>Skipped.<crlf>$tkn WAS found in<crlf>$input.";
}
}
Code: Select all
////////////////////////////////////////////////////////////////////////////////////
//Test 3: how-to check case in-sensitive.
$blacklist = "Seat,Fiat,Skoda";
$input = "My new car is an SKODA";
foreach($tkn, $blacklist, ",")
{
if ($tkn==""){break;}
//not case-sensitive:
$tkn = recase($tkn, "lower");
$input = recase($input, "lower");
if strpos($input,$tkn) == -1 )
{
msg "Test 3<crlf 2>Continue.<crlf>$tkn was NOT found in<crlf>$input.";
}else{
msg "Test 3<crlf 2>Skipped.<crlf>$tkn WAS found in<crlf>$input.";
}
}
Code: Select all
////////////////////////////////////////////////////////////////////////////////////
//Test 4: more practically use by separating function from result.
$blacklist = "Seat,Fiat,Skoda";
$input = "My new car is an AUDI";
foreach($tkn, $blacklist, ","){ if ($tkn==""){break;}
$tkn = recase($tkn, "lower"); $input = recase($input, "lower");
if strpos($input,$tkn) == -1 ) {$found = false;}else{$found = true; break;}
//(Note that we break; the loop once we are True)
}
if ( ! $found)
{
msg "Test 4<crlf 2>not found";
}
else
{
msg "Test 4<crlf 2>found";
}
Code: Select all
////////////////////////////////////////////////////////////////////////////////////
//Test 5: like Test4 but as an separate function:
global $blacklist, $input, $FuncResult;
$blacklist = "Seat,Fiat,Skoda";
$input = "My new car is an FIAT";
sub "_function";
if ( ! $FuncResult){
msg "Test 5<crlf 2>not found";
}else{
msg "Test 5<crlf 2>found";
}
//////////////////////////
"_function"
global $blacklist, $input, $FuncResult;
foreach($tkn, $blacklist, ","){ if ($tkn==""){break;}
$tkn = recase($tkn, "lower"); $input = recase($input, "lower");
if strpos($input,$tkn) == -1 ) {$FuncResult = false;}else{$FuncResult = true; break;}
}