Question about strpos in PHP

后端 未结 2 442
臣服心动
臣服心动 2020-12-21 12:41

I\'m just trying to figure that out...

$mystring = \"/abc/def/hij\";
$find = \"/abc\";

echo(strpos($mystring, $find) . \"
\"); if (strpos($mystrin
相关标签:
2条回答
  • 2020-12-21 13:19

    Test using the !== operator. This will compare types and values, as opposed to just values:

    $mystring = "/abc/def/hij";
    $find = "/abc";
    
    echo(strpos($mystring, $find) . "<br>");
    if (strpos($mystring, $find) !== false) {
        echo("found");
    } else {
        echo("not found");
    }
    
    0 讨论(0)
  • 2020-12-21 13:34

    I found what the problem was... I need to use !== false instead of != ... Aaaah, php.

    0 讨论(0)
提交回复
热议问题