php problem: strpos function not working

前端 未结 7 1475
鱼传尺愫
鱼传尺愫 2020-12-21 00:14

why is the following php code not working:

$string = \"123\";
$search = \"123\";

if(strpos($string,$search))
{
    echo \"found\";
}else{
    echo \"not fou         


        
7条回答
  •  轮回少年
    2020-12-21 00:55

    From the manual:

    This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

    In your example, you should use

    $string = "123";
    $search = "123";
    
    if ( false !== strpos( $string, $search ) ) {
        echo "found";
    } else {
        echo "not found";
    }
    

提交回复
热议问题