Tuesday, 10 September 2013

Find first occurence of substring before a certain position

Find first occurence of substring before a certain position

In PHP, if I have a long string, IE 10'000 chars, how would you suggest I
go about finding the first occurence of a certain string before and after
a given position.
IE, if I have the string:
BaaaaBcccccHELLOcccccBaaaaB
I can use strpos to find the position of HELLO. How could I then go about
finding the position of the first occurence of B before HELLO and the
first occurence of B after HELLO?

No comments:

Post a Comment