1

i've few PHP files and i want to read but not execute these files to fetch function list from them, i can use include and then get_class_methods by calling a class but i don't want to do that, i simply just want to read php file and extract function list, i tried some RegEx patterns but it also matches in strings which i dont want.

I used following RegEx pattern but dont want to use it though it dont seems that the solution would be RegEx:

preg_match_all("%function ([^(\s]+)%", $source, $func);`
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274

1 Answers1

0

Two options:

  1. get regex buddy and play around with your regex until it does what it needs to

  2. implement the following algorithm:

    1. search for the string "function"
    2. get the characters to the right of function until you encounter " " (whitespace)
    3. when you encounter the "{" after the function name and arguments, declare $c = 1
    4. for each "{" you encounter, increment $c
    5. for each "}" you encounter, decrement $c
    6. when $c == 0, you have reached the end of the function
    7. save the function in a variable
    8. repeat
andypopa
  • 536
  • 6
  • 15