tags:

views:

57

answers:

3

i know you can find the first and last occurrence in a string using strstr() and strchr but how do i find the second occurrence, and the third occurrence of needle inside haystack? im using this to find the last occurrence of needle and the first occurrence of another needle and their position, then return the string that is in between each. thank you.

+2  A: 

You can use strpos() and update the offset value to be after whatever you just matched.

webdestroya
+1  A: 

You must find by strstr(), get result and start finding from result for time when strstr dont find nothing new.

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

Svisstack
A: 

For the last occurrence, use strrpos.

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

It takes an optional offset argument too.

Matthew Flaschen