Possible Duplicate:
Parse PHP code to extract function names?
I’m working on a script to read my PHP files and get all the functions as a return.
I’m using preg_split() to split my file into an array of functions.
I’m having trouble writing the pattern to get all the functions returned (faced issue when the function’s name contains the word ‘function’. I’m open to any other solutions / advice.
Expected output:
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}'
)
You can try something like this to capture just the names / declarations:
Or this to include the body of the function (assuming they’re on a single line like in your example):
It works for all of your test cases, and without any sample input or more details, I can’t elaborate further.