- preg_replace_callback: documentation ( source)
<?php
class Foo
{
function escape($str)
{
return '`' . $str . '`';
}
function bar()
{
$str = 'hello world !';
return preg_replace_callback('~\w+~', function($m){
return $this->escape($m[0]);
}, $str);
}
}
$foo = new Foo();
echo $foo->bar();