- preg_match_all: documentation ( source)
- var_export: documentation ( source)
<?php
$text = 'some text [person name="Jackson" family="Smith"] text [vehicle brand="Benz" type="SUV" doors="4" seats="7"]';
foreach (preg_match_all('~(?:\G(?!^)|\[(\w+)) (\w+)="(\w+)"~', $text, $out, PREG_SET_ORDER) ? $out : [] as $matches) {
if ($matches[1]) {
$tag = $matches[1];
}
$result[$tag][$matches[2]] = $matches[3];
}
var_export($result);