phpstrpos

A truthy check on the return value of strpos() fails to find match at start of haystack string


I have a string like

DTSTART;VALUE=DATE:20190208

and I want to use the PHP function strpos() to find

DTSTART;VALUE=DATE:

this works only if I remove the semicolon

I tried

if(strpos($subValue, "DTSTART;VALUE=DATE:")){

and also with (1, 2, 3 times) escaping the semicolon

strpos($subValue, "DTSTART\;VALUE=DATE:")
strpos($subValue, "DTSTART\\;VALUE=DATE:")
strpos($subValue, "DTSTART\\\;VALUE=DATE:")

I tried stripos() and also single quotes instead of double quotes, no success.


Solution

  • strpos will return 0 because needle is found in position 0, and 0 is false value that why you have to use value and the data type comparison (===)

    if (strpos($subValue, 'DTSTART;VALUE=DATE:') !== false) {