Possible Duplicate:
A PHP regex to extract php functions from code files
I have a file with a list of functions formatted something like this:
function foo(){
...code { code{} } code...
}
For this particular file I will always place the word 'function' all the way to the left and the ending curly brace all the way to the left. As is customary, the code within the function will always be indented. The code within the function may contain any character including curly braces.
I would like to parse the file with PHP to get an associative array of functions where the names of the functions are the keys. I just started with this, here is a very simple start:
$regex = "/function.*/";
preg_match_all($regex, $str, $result, PREG_PATTERN_ORDER);
$arr = $result[0];
print_r($arr);
This produces the following and stops at each new line:
Array
(
[0] => function foo(){
[1] => function bar(){
[2] => function stop(){
[3] => function go(){
)
I tried changing the regex to:
$regex = "/function.*\n}$/s";
My thinking was that where there is a new-line character directly follwed by a ending-curly brace, \n}$ would match the end of the function. However, this does not work, it produces an array with one long element that contains everything after function foo()
I have not started to get the function name into the key of the associative array.