Given a string with attribute/value pairs such as
attr1="some text" attr2 = "some other text" attr3= "some weird !@'#$\"=+ text"
the goal is to parse it and output an associative array, in this case:
array('attr1' => 'some text',
'attr2' => 'some other text',
'attr3' => 'some weird !@\'#$\"=+ text')
Note the inconsistent spacing around the equal signs, the escaped double quote in the input, and the escaped single quote in the output.
Try something like this:
which produces:
And a short explanation:
EDIT: This regex fails if the value ends in a backslash like
attr4="something\\"
I don't know PHP, but since the regex would be essentially the same in any language, this is how I did it in ActionScript:
And I got the following out put: