Forum Moderators: coopster
Im using preg_replace_callback() to try to call a function within the same class:
e.g.
[code]
class a {
function a() {
preg_replace_callback($reg_ex, "b", $text);
}
function b() {
// This is the call back function I want to call from preg_replace_callback
}
}
I've tried putting the callback function as "b", "a::b", "this->b" but no luck. how do i call a callbackfunction from within the same class?
Cheers
<?phpIf you copy and paste this to test, don't forget to replace the broken pipe (¦) symbol by rekeying it as the forum breaks the pipe symbol.
class a {
function a($text)
{
echo preg_replace_callback("¦(\d{2}/\d{2}/)(\d{4})¦", array(&$this, 'b'), $text);
}
function b(&$matches)
{
return $matches[1].($matches[2]+1);
}
}
$text = "April fools day is 04/01/2002\n";
$text.= "Last christmas was 12/24/2001\n";
$var = new a($text);
?>
I noticed I left an unnecessary reference in there too, no need for the ampersand sign on the second function parameter, $matches:
function b($matches)