recherche

Maison  >  Questions et réponses  >  le corps du texte

php - preg_replace_callback 如何回调一个实例方法啊

mixed preg_replace_callback ( mixed $pattern , callable $callback , mixed $subject [, int $limit = -1 [, int &$count ]] )

这个函数的$callback,传字符串进去就可以调用,静态方法什么的。那么怎么能指定成一个实例方法呢?

巴扎黑巴扎黑2897 Il y a quelques jours406

répondre à tous(1)je répondrai

  • PHPz

    PHPz2017-04-10 13:13:23

    完全可以啊,使用数组传递就行

    class A
    {
        public function test($matches)
        {}
    }
    
    $a = new A();
    preg_replace_callback("/(w+)/", array($a, 'test'), 'asfdasdf asdfsad');

    répondre
    0
  • Annulerrépondre