1

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:

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.

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

you need a regular expression: maybe something like this

preg_match("[a-zA-Z_][a-zA-Z_0-9]*(.*)",$stringToLookIn);

Comments

0
preg_match_all('/([a-zA-Z_]\w+)\s*\(/', $source, $match);
var_dump($match[1]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.