Search code examples
phpregexstringtext-parsing

Parse multiple predictably formatted substrings of user data existing in a single string


I have a really long string in a certain pattern such as:

userAccountName: abc userCompany: xyz userEmail: a@xyz.com userAddress1: userAddress2: userAddress3: userTown: ...

and so on. This pattern repeats.

I need to find a way to process this string so that I have the values of userAccountName:, userCompany:, etc. (i.e. preferably in an associative array or some such convenient format).

Is there an easy way to do this or will I have to write my own logic to split this string up into different parts?


Solution

  • I think the solution closest to what I was looking for, I found at http://www.justin-cook.com/wp/2006/03/31/php-parse-a-string-between-two-strings/. I hope this proves useful to someone else. Thanks everyone for all the suggested solutions.