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));
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
array(4) { [0]=> string(8) "/tellraw" [1]=> string(24) "@a[name="Arie1906", c=1]" [2]=> string(15) "quoted "你好"" [3]=> string(42) "{"rawtext": [{"text":"§bI am blue"}]}" }
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
83.41 ms | 407 KiB | 5 Q