I’ve got a string that I need to parse into an array in PHP. The string looks something like this:
(Key: ALL_HTTP)(Value:HTTP_HOST:10.1.1.1 )(Key: ALL_RAW)(Value:Host: 10.1.1.1:80 )(Key: APPL_MD_PATH)(Value:/ROOT)(Key: AUTH_TYPE)(Value:)(Key: AUTH_USER)(Value:)(Key: AUTH_PASSWORD)(Value:)(Key: LOGON_USER)(Value:)(Key: REMOTE_USER)(Value:)
The number of “key/value” pairs could be unlimited but is usually about 30-40 per string.
I’ve been playing with preg_match and a variation of an example from PHP.net – something like this:
preg_match('/(\S+): (\S+)/', $string, $result);
That gets me back the first key as $result[0] but doesn’t help for the rest.
If anyone could help me with a proper expression that would be fantastic. I’d also appreciate any good reading resources for splitting strings with PCRE.
Thanks all!
Try something along the lines of
You probably don’t need the ALL lines.
Based on your sample string, you might like this regex better: