preg_split PHP 文件模式正则表达式中的 PHP 函数


preg_split php function in a php file pattern regexp

可能的重复项:
解析 PHP 代码以提取函数名称?

我正在编写一个脚本来读取我的 PHP 文件并获取所有函数作为返回。

我正在使用preg_split()将我的文件拆分为一系列函数。

我在编写模式以返回所有函数时遇到问题(当函数名称包含"函数"一词时遇到问题。我对任何其他解决方案/建议持开放态度。

预期产出:

array (
  0 => 'function write{$oneparam, $two, $three){return $two}',
  1 => 'function read{$oneparam, $two, $tthree){returne $awesome}',
  2 => 'function edit{$oneparam, $two, $three){return $two},
  3 => 'function delete{$oneparam, $two, $three){return $two}',
  4 => 'function lastfunction{$oneparam, $two, $three){return $two}'
)

您可以尝试这样的方式来仅捕获名称/声明:

#(function's+'w+'(.*?')#s

或者这包括函数的主体(假设它们像您的示例中一样在一行上):

#(function's+'w+'(.*?')'s*{.*?})#s

它适用于所有测试用例,没有任何示例输入或更多详细信息,我无法进一步详细说明。