Finding used functions from php source file
Basically I want to find a function from a php string source content. I'm trying to parse a php file and read its content into string. I want to find something like:
开发者_JAVA技巧function_name(paras)
or function_name()
or function_name(params, params)
for example if source contains:
echo 'Greetings'.greet("I'm Johan");
$age = date_of_birth(date());
echo 'I am ' .$age . 'years old';
it would then find greet
, date_of_birth
, date
because these are the functions used.
If you want to get the parameters including nested brackets, like your date_of_birth(date())
, its maybe not impossible with regex but very difficult.
If you say its enough to find the name of the function then you can try this:
\w+(?=\()
See it here on Regexr
That will match at least one word character that is followed by an opening bracket.
\w
contains letters, digits and the underscore
(?=\()
is a positive look ahead that checks if a (
is following
you need a regular expression: maybe something like this
preg_match("[a-zA-Z_][a-zA-Z_0-9]*(.*)",$stringToLookIn);
preg_match_all('/([a-zA-Z_]\w+)\s*\(/', $source, $match);
var_dump($match[1]);
精彩评论