PDA

View Full Version : trouble with srtpos()


Antivirus
06-05-2007, 02:07 PM
Having trouble testing strpos below:


$haystack = '11,20';
$needle = '1';

if (strpos($haystack, $needle) !== false) {
return true;
}
else {
return false;
}


It's returning true because the '1' is within the haystack (11,20) however i only want it to return true if the needle is '11', not 1. Is there a different function i should be using to test for a numeric value within a string?
Thanks!

solved... needed to encapsulate the needle and haystack then do the strpos check, as follows:


$haystack = '11,20';
$needle = '1';

if (strpos(",$haystack,", ",$needle,") !== false) {
return true;
}
else {
return false;
}


:)