3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parseQuoteAware(string $commandLine) : array{ $args = []; preg_match_all('/"((?:\\\\.|[^\\\\"])*)"|[~^][^\s~^]*|\S+\s*/u', $commandLine, $matches, PREG_UNMATCHED_AS_NULL); $size = count($matches[0]); for ($k = 0; $k < $size; ++$k) { if ($matches[1][$k] !== null) { $args[] = str_replace('\"', '"', $matches[1][$k]); continue; } $match = $matches[0][$k]; $level = (substr_count($match, "[") - substr_count($match, "]")) + (substr_count($match, "{") - substr_count($match, "}")) + (substr_count($match, "(") - substr_count($match, ")")); if ($level == 0 || $k == $size - 1) { $args[] = rtrim($match); } else { $matches[0][$k + 1] = $match . $matches[0][$k + 1]; } } return $args; } $cmdLine = '/tellraw @a[name="Arie1906", c=1] "quoted \"你好\"" {"rawtext": [{"text":"§bI am blue"}]}'; var_dump(parseQuoteAware($cmdLine));

preferences:
45.95 ms | 408 KiB | 5 Q