0

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?

3
  • What do you need it for? Commented Jul 10, 2009 at 20:27
  • 2
    You'd probably be better off using Notepad++ or some other tool to refactor your code in this manner Commented Jul 10, 2009 at 20:27
  • You're setting yourself up for a lot more work than need be. There should never be a time in you life when you think that writing regex to parse through HTML is a good idea. Ever. It's simply a waste of time. Go with what Josn Rasch said... use an editor and do a find and replace. Commented Jul 11, 2009 at 0:04

2 Answers 2

1

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.

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

Comments

1

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.

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.