At first, your line seems to skip the quote. Cm.
&user_1382926="Mike",Smith"
Secondly, using an explosion seems like a bad idea, as you will explode and = inside the specified fields.
The way I usually approach this is a state machine. Using a regular expression (see PHP - breaking lines in Key / Value pairs ) is much simpler.
The language you are trying to match is as follows:
- Keys can consist of 1 or more alphanumeric characters or underscores.
- Values ββare a list of quoted strings separated by commas.
- Keys and values ββare separated by an equal sign
- A pair of key values ββis separated by &
A regular expression to get the value of a key value:
$regex = '/&?([^=]+)=([^&]+)/'; preg_match_all($regex, $header, $r); $result = array_combine($r[1], $r[2]);
The first entry in $ result will contain the key 'header' and the value '' firstname ',' lastname ''.
Now we just need to convert the values ββof the result from a string to a list of strings.
foreach ($result as $key => $value) { $regex = '("[^"]+")'; preg_match_all($regex, $value, $r); $result[$key] = $r; }
In this case, some boundary cases are missing, such as escaped quotation marks inside values, but they should work in most cases.
In your example, this produces:
Array ( [heading] => Array ( [0] => "firstname" [1] => "lastname" ) [user_1382926] => Array ( [0] => "Mike" [1] => "Smith" ) [user_1383059] => Array ( [0] => "Sonny" [1] => "Williams" ) [user_1303EM000014] => Array ( [0] => "Mike" [1] => "Jones" ) )