3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pattern = " /\[ (?:block:(?<block>piechart)) (?: (?:\s+value:(?<value>[0-9]+)) | (?:\s+stroke:(?<stroke>[0-9]+)) | (?:\s+angle:(?<angle>[0-9]+)) | (?:\s+colorset:(?<colorset>reds|yellows|blues)) )* \]/xumi"; $subject = "here is a block to be replaced [block:piechart value:25 angle:0] [block] and another one [block:piechart colorset:reds value:20]"; preg_replace_callback($pattern, 'callbackFunction', $subject, -1, $count, PREG_UNMATCHED_AS_NULL); function callbackFunction($matches) { var_dump(array_filter($matches, function ($v) { return !is_null($v); })); // process matched values, return some replacement... $replacement = "..."; return $replacement; };
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
array(7) { [0]=> string(35) "[block:piechart value:25 angle:0]" ["block"]=> string(8) "piechart" [1]=> string(8) "piechart" ["value"]=> string(2) "25" [2]=> string(2) "25" ["angle"]=> string(1) "0" [4]=> string(1) "0" } array(7) { [0]=> string(39) "[block:piechart colorset:reds value:20]" ["block"]=> string(8) "piechart" [1]=> string(8) "piechart" ["value"]=> string(2) "20" [2]=> string(2) "20" ["colorset"]=> string(4) "reds" [5]=> string(4) "reds" }

preferences:
119.03 ms | 408 KiB | 5 Q