PHP find first of occurrence of string

Posted by mike on Stack Overflow See other posts from Stack Overflow or by mike
Published on 2010-04-16T01:39:48Z Indexed on 2010/04/16 1:43 UTC
Read the original article Hit count: 467

Filed under:
|

I have a string of data like below and I've been struggling trying to figure out how to split it up so that I can use it efficiently.

"United States FirstName: Mike LastName: Wolf City: Chicago"

I need to split up the string in to substrings and the list may not always be in the same order.

For example it could vary like below:

"United States City: Chicago FirstName: Mike LastName: Wolf"
"United States FirstName: City: Chicago Mike LastName: Wolf"

I need to find which parameter comes first after 'United States'. It could be 'City:', 'FirstName:' or 'LastName:'. And, I also need to know the start position of the first parameter.

Thanks in advance!

© Stack Overflow or respective owner

Related posts about php

Related posts about substring