Home > Backend Development > PHP Tutorial > preg_replace_callback 如何回调一个实例方法啊

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

WBOY
Release: 2016-06-06 20:52:07
Original
898 people have browsed it

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

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

回复内容:

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

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

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

class A
{
    public function test($matches)
    {}
}

$a = new A();
preg_replace_callback("/(w+)/", array($a, 'test'), 'asfdasdf asdfsad');
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template