I understand that this function will get the first occurrence of the string.
But what I want is the 2nd occurrence.
How to go about doing that?
I understand that this function will get the first occurrence of the string.
But what I want is the 2nd occurrence.
How to go about doing that?
You need to specify the offset for the start of the search as the optional third parameter and calculate it by starting the search directly after the first occurrence by adding the length of what you're searching for to the location you found it at.
$pos1 = strpos($haystack, $needle);
$pos2 = strpos($haystack, $needle, $pos1 + strlen($needle));
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1); // $pos = 7, not 0
You can try this, though I havent test it out-
$pos = strpos($haystack, $needle, strpos($haystack, $needle)+strlen($needle));