The regular expression should be fixed.
[
and]
should be escaped to match them literally. ([
,]
have special meaning in regular expression).
The code is calling _parse_quote
instead of passing the function to the preg_replace_callback
. Just pass the function name as string.
You can access the captured group by indexing. ($matches[2]
to get the second captured group)
$str = '[quote id=123]This is a quote tag[/quote]';
$str = preg_replace_callback("^\[quote id=([0-9]+)\](.*?)\[/quote\]^", "_parse_quote", $str);
echo $str;
function _parse_quote($matches) {
$str = '<blockquote>' . $matches[2] . '</blockquote>';
return $str;
}
output:
<blockquote>This is a quote tag</blockquote>