php problem: strpos function not working

前端 未结 7 1452
鱼传尺愫
鱼传尺愫 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 01:04

    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

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