3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = 'some text [person name="Jackson" family="Smith"] text [vehicle brand="Benz" type="SUV" doors="4" seats="7"] and [invalid closed="false" monkeywrench [lonetag] text [single gender="female"]'; foreach (preg_match_all('~\[(\w+)(?=(?: \w+="\w+")*])(]?)|(?:\G(?!^) (\w+)="(\w+)")~', $text, $out, PREG_SET_ORDER) ? $out : [] as $matches) { if ($matches[2]) { $result[$matches[1]] = []; } elseif (!isset($matches[3])) { $tag = $matches[1]; } else { $result[$tag][$matches[3]] = $matches[4]; } } var_export($result);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'person' => array ( 'name' => 'Jackson', 'family' => 'Smith', ), 'vehicle' => array ( 'brand' => 'Benz', 'type' => 'SUV', 'doors' => '4', 'seats' => '7', ), 'lonetag' => array ( ), 'single' => array ( 'gender' => 'female', ), )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
119.81 ms | 406 KiB | 5 Q