php problem: strpos function not working

前端 未结 7 1478
鱼传尺愫
鱼传尺愫 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:39

    strpos returns the numeric position of the string you want to search for if it finds it. So in your case, you want to be doing this instead:

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

    basically it returns a false if it doesn't find your string

提交回复
热议问题