Tim*_*rst 2 php regex static-analysis function
我正在尝试使用PHP正则表达式从php源代码中提取函数.到目前为止,我使用递归正则表达式来提取{}之间的所有内容,但它也匹配像if语句之类的东西.当我使用类似的东西:
preg_match_all("/(function .*\(.*\))({([^{}]+|(?R))*})/", $data, $matches);
Run Code Online (Sandbox Code Playgroud)
当文件中有多个函数时,它不起作用(可能是因为它在递归中也使用了'function'部分).
有没有办法做到这一点?
示例文件:
<?php
if($useless)
{
echo "i don't want this";
}
function bla($wut)
{
echo "i do want this";
}
?>
Run Code Online (Sandbox Code Playgroud)
谢谢