I want to remove a specific function which is void (doesn't return anything) from my javascript source code using php at run time. Consider the following js code which is supposed to be outputted by php:
var a = func1(x1);
func2(a + ": " + x1);
// other codes
func2(someOther("Lol") + x1);
// other codes
here I want to remove func2 (it is something like a log function which outputs something to js console).
Now first thing that came to my mind was writing a regex and replace it with an empty string using preg_replace. But I wasn't successful in defining the right expression. I was wondering that is it possible to write a regex to match the function calls? If it is could you please give me some hints or examples so that I could use it?
And if you think that there is an alternative way of doing it, I'd appreciate to hear yours.
Notes
- The function is not used in complicated structures like
ifconditions and etc. (I mean you don't need to consider these situations) - It is possible to call other functions inside this one (as arguments)
- I can not change js codes. (they are submitted by other people)
func2 = function (a) {};