开发者

occurrence of string

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 need开发者_JAVA百科le and their position, then return the string that is in between each. thank you.


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


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


For the last occurrence, use strrpos.

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

It takes an optional offset argument too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜