How To Bulk Edit 100's of PHP files?

jbarrett

Regular Member
Joined
Jul 21, 2011
Messages
344
Reaction score
571
Hi

I have around 1000 php files where I need to replace about 10 lines of code with new code. Is there a tool that can be used to do this?? I saw notepad++ can do this but it is limited to replacing 1 line at a time which I can not do as I need to do 10 lines at the same time.

Thanks
 
is it the same 10 lines of code in each file?
 
Er, not necessarily one line at a time if you read up on it. Say this is your code:
Code:
public void myFunction(String theArgument) {
     // do cool stuff
     return 1;
}

With extended searching in Notepad++, the search phrase is:
Code:
public void myFunction(String theArgument) {\r\n\t// do cool stuff\r\n\treturn 1;\r\n}
because each line break is replaced with "\r\n" and each tab is "\t"

Seems like a pain, but if you copy your original code into a new file, turn on extended searching, you can do the following searches:
  • Search "\r\n" and replace with "//r//n"
  • Search "\t" and replace with "//t"
  • Turn on normal searching
  • Search "//r//n" and replace with "\r\n"
  • Search "//t" and replace with "\t"

If you ask why you replace \r\n with //r//n, it's because if you were to replace \r\n with \r\n, it would stay the same and keep the line break. And you have to switch to normal in the middle of it because if you stay in extended and replace //r//n with \r\n it will just put the line break back.

Anyway, this spits out, say, originalCode in single line format. And repeat with your new code (returns newCode). Then you turn on extended searching and replace originalCode with newCode.
 
Last edited:
thanks artizhay that was exactly what I was looking for
 
Notepad or Dreamweaver is allowing you to do it in a blink :

Ctrl + F

Find in a file / folder
Select your folder
Paste your code
Paste your modified code
Click ok / run

And that's it
 
This is easy depending on what exactly you need to do..
I like sharepoint 2007

But you can use a free version of cyberduck.

You just need to connect via ftp then let cyberduck index all your files remotely. (you can do this local too)
once done you can do a find and replace ALL..
I use this method when im unhacking sites now. works good..
 
Do you have PHP experience?

If yes, why don't you solve this with PHP. All neccessary functions for this are included.


Randolph
 
Back
Top