正则表达式。在php中查找函数名称

时间:2017-11-08 13:25:24

标签: php find expression syntax-highlighting

我想编写用于查找php函数名的正则表达式语法:

例如:

public function _c_Def()
{

}

我想得到:

_c_Def

我尝试了什么:

/function[\s\n]+(\S+)[\s\n]*\(/
(?:^|\n)function ([^\s]+)

但每次我都错过了什么

1 个答案:

答案 0 :(得分:1)

您可以使用PHP Reflection API获取类中的所有方法,而不是仅通过regexp解析它。

$class = new ReflectionClass('Namespace\YourClassName');
$methods = $class->getMethods(ReflectionMethod::IS_PUBLIC);

http://php.net/manual/en/book.reflection.php