here I have my regexp which founds all instances of 4chan style quoting (e.g. >10, >59, >654564) and just returns it as pattern output. My question is, is it possible to insert my pattern output...
\1
...into PHP function.
While this is working fine:
$a = preg_replace('`(>\d+)`i', '\1', $b);
Something I am looking for is not:
$a = preg_replace('`(>\d+)`i', '".getpost('\1')."', $b);
Example [php >= 5.3.0] (with use of Closure):
$callback = function($match) {
return "{" . $match[1] . "}"; # do smth with match
};
$string = 'test1 >1 test2 >12 test3 >123 test4';
echo preg_replace_callback('~(>\d+)~i', $callback, $string);
will output:
test1 {>1} test2 {>12} test3 {>123} test4
Example [php < 5.3.0]:
function replaceCallback($match) {
return "{" . $match[1] . "}"; # do smth with match
};
$string = 'test1 >1 test2 >12 test3 >123 test4';
echo preg_replace_callback('~(>\d+)~i', 'replaceCallback', $string);