why is the following php code not working:
$string = \"123\";
$search = \"123\";
if(strpos($string,$search))
{
echo \"found\";
}else{
echo \"not fou
strpos
returns the first offset where $search
was found - 0
. 0
in turn evaluates to false
. Therefore the if fails.
If $search
was not found, strpos
returns FALSE
. First check the return value for !== FALSE
, and then check the offset.
Thanks to everyone who pointed this out in the comments.
see: http://php.net/manual/en/function.strpos.php