【发布时间】:2012-06-01 23:33:21
【问题描述】:
我正在编写一个脚本来读取我的 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}'
)
【问题讨论】:
-
使用正则表达式解析编程语言是个坏主意。
-
你应该使用
preg_match_all。不过,为了更准确的结果,tokinizer。让我寻找重复... -
这只是为了记录目的,我想记录我的所有功能
-
不要使用正则表达式,而是使用PHP tokenizer。
-
马里奥 你的回答是对的。这是我的错误。 preg_match_all 完美运行。我道歉
标签: php regex pattern-matching preg-split