tags:

views:

91

answers:

2

I want to use PHP to replace javascript functions in HTML documents. For example:

original:

function my_function(hey) {
    do stuff
}

new:

function new_function(hi) {
    do different stuff
}

I was thinking of using regular expressions with the ereg_replace function, but I'm not sure if this is the best approach. The code in each function is pretty long... plus regex looks very daunting to me at the moment. Any suggestions?

+1  A: 

Looks like you trying to do something pointless. Put a new function and call it. Just do no use the old one, once you anyway want to replace the entire body with it's name.

Artem Barger
+1  A: 

This is the kind of thing that perl is built for. Spend a day learning how to slurp in files and take a good look at the many regex tools out there, and you'll have yourself a script that you can modify to use in the future, if need be, but is otherwise throwaway, which is good, since you probably wrote it crappily, being your first one and all.

Xiong Chiamiov