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.
views:
57answers:
3
+2
A:
You can use strpos()
and update the offset
value to be after whatever you just matched.
webdestroya
2010-04-19 22:52:58
+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
2010-04-19 22:53:53
A:
For the last occurrence, use strrpos
.
$lastPos = strrpos($haystack, $needle);
It takes an optional offset argument too.
Matthew Flaschen
2010-04-19 22:54:21