Let’s say my string is:
$str = "abcdefg foo() hijklmopqrst";
How do I let PHP call the function foo() and insert the returning string to the rest of that string?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
output:
This will allow any lower-case letters as function name. If you need any other symbols, add them to the pattern, i.e.
[a-zA-Z_].Be VERY careful which functions you allow to be called. You should at least check if $m[1] contains a whitelisted function to not allow remote code injection attacks.
Testrun on
"abcdefg foo() bat() hijklmopqrst"outputs"abcdefg bar bat() hijklmopqrst".Optimisation for whitelisting approach (building pattern dynamically from allowed function names, i.e.
(foo|bar).