Connecting Tech Pros Worldwide Help | Site Map

preg_replace_callback, how to use in object ?

Snaggy
Guest
 
Posts: n/a
#2: Jun 2 '08

re: preg_replace_callback, how to use in object ?


this is my problem:

Class myClass {

function process($matches) {return something($matches);}

function myReplace($input)
{
return preg_replace_callback(/pattern/, '$this->process', $input)
}
}

problem is '$this->process' isn't a valid callback.

How can I do this?
ZeldorBlat
Guest
 
Posts: n/a
#1: Jun 2 '08
On Apr 14, 9:34 am, Snaggy <l.cio...@gmail.comwrote:
Quote:
this is my problem:
>
Class myClass {
>
function process($matches) {return something($matches);}
>
function myReplace($input)
{
return preg_replace_callback(/pattern/, '$this->process', $input)
>
}
}
>
problem is '$this->process' isn't a valid callback.
>
No, but this is:

array($this, 'process')
valentin.frechaud@free.fr
Guest
 
Posts: n/a
#3: Jun 2 '08

re: preg_replace_callback, how to use in object ?


On 14 avr, 15:34, Snaggy <l.cio...@gmail.comwrote:
Quote:
this is my problem:
>
Class myClass {
>
function process($matches) {return something($matches);}
>
function myReplace($input)
{
return preg_replace_callback(/pattern/, '$this->process', $input)
>
}
}
>
problem is '$this->process' isn't a valid callback.
>
How can I do this?
Hi,

You can do this :

preg_replace_callback( /pattern/, array($this, 'process'), $input);

Ci@
Closed Thread