PHP strpos() function returning incorrect result

前端 未结 1 694
情深已故
情深已故 2021-01-28 04:28

I am simply trying to see if a numeric year is contained inside a string of car years and models. I would think the following code should show $my_str as FALSE. But it return

1条回答
  •  孤街浪徒
    2021-01-28 04:49

    You can't search for an INT inside a string using this function, you could convert the int to string before searching, like this:

    $my_haystack = "2007 Cadillac CTS";
    $my_needle = 1900;
    $my_str = strpos($my_haystack, strval($my_needle));
    

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