Line appearing

I know you can find the first and last occurrence in a string using strstr()

and strchr

, but how do you find the second occurrence and third occurrence of a needle in a haystack? im using this to find the last occurrence of a needle and the first occurrence of another needle and their position, then return the string that is in between. thanks.

+2


a source to share


3 answers


You can use strpos()

and update the value offset

that should be after everything you just agreed upon.



+2


a source


You have to find strstr (), get the result, and start searching from the result in the time that strstr finds nothing new.



You can use for it: http://php.net/manual/en/function.strpos.php

+1


a source


In the latter case, use strrpos

.

$lastPos = strrpos($haystack, $needle);

      

It also accepts an optional offset argument.

0


a source







All Articles