Created
July 29, 2015 18:33
-
-
Save cgray/c348928f619b3eb68103 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$subject = <<<DATA | |
property=value property2="value2" property3='value3' | |
DATA; | |
$pattern = '( | |
(?:^|\s) | |
(?<name>[a-z]\w+) | |
(?:=) | |
(?:(?J) | |
(?:\'(?<value>[^\']+)\')| | |
(?:"(?<value>[^"]*)")| | |
(?<value>[^\s,]+) | |
) | |
)xiu'; | |
preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER); | |
$result = []; | |
foreach ($matches as $match) { | |
$result[$match['name']] = $match['value']; | |
} | |
var_dump($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
preg to get an associative array from a htmlesqe attribute string