preg_replace_callback, how to use in object ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Snaggy

    preg_replace_callback, how to use in object ?

    this is my problem:

    Class myClass {

    function process($matche s) {return something($matc hes);}

    function myReplace($inpu t)
    {
    return preg_replace_ca llback(/pattern/, '$this->process', $input)
    }
    }

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

    How can I do this?
  • ZeldorBlat

    #2
    Re: preg_replace_ca llback, how to use in object ?

    On Apr 14, 9:34 am, Snaggy <l.cio...@gmail .comwrote:
    this is my problem:
    >
    Class myClass {
    >
    function process($matche s) {return something($matc hes);}
    >
    function myReplace($inpu t)
    {
    return preg_replace_ca llback(/pattern/, '$this->process', $input)
    >
    }
    }
    >
    problem is '$this->process' isn't a valid callback.
    >
    No, but this is:

    array($this, 'process')

    Comment

    • valentin.frechaud@free.fr

      #3
      Re: preg_replace_ca llback, how to use in object ?

      On 14 avr, 15:34, Snaggy <l.cio...@gmail .comwrote:
      this is my problem:
      >
      Class myClass {
      >
      function process($matche s) {return something($matc hes);}
      >
      function myReplace($inpu t)
      {
      return preg_replace_ca llback(/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_ca llback( /pattern/, array($this, 'process'), $input);

      Ci@

      Comment

      Working...