3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = ' <div class="temp"> [title type="text" tag="h2" value="This is my cool title" disabled some-attribute] [text type="text" tag="p" value="Lorem ipsum dolor sit amet"] </div> '; preg_match_all('/\[(.*?)\]/', $html, $matches); $result = []; foreach ($matches[1] as $match) { $id = strtok($match, ' '); $tag = ['id' => $id]; while ($token = strtok(' ')) { if (str_contains($token, '=')) { [$key, $value] = explode('=', $token); if (str_ends_with($token, '"')) { $tag[$key] = trim($value, '"'); continue; } $value2 = strtok('"'); $tag[$key] = trim("$value $value2", '"'); continue; } $tag[$token] = true; } $result[] = $tag; } print_r($result);

preferences:
39.39 ms | 410 KiB | 5 Q