- var_dump: documentation ( source)
- preg_replace_callback: documentation ( source)
- array_filter: documentation ( source)
<?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;
};