1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How To Bulk Edit 100's of PHP files?

Discussion in 'Web Design' started by jbarrett, Jan 24, 2012.

  1. jbarrett

    jbarrett Registered Member

    Joined:
    Jul 21, 2011
    Messages:
    98
    Likes Received:
    40
    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
     
  2. Anton91

    Anton91 Junior Member

    Joined:
    Aug 7, 2011
    Messages:
    161
    Likes Received:
    44
    Home Page:
    Write a script
     
  3. fizzik

    fizzik Registered Member

    Joined:
    Apr 26, 2010
    Messages:
    53
    Likes Received:
    15
    Location:
    .au
    is it the same 10 lines of code in each file?
     
  4. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    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.
     
    • Thanks Thanks x 2
    Last edited: Jan 24, 2012
  5. Hunwarrior

    Hunwarrior Jr. VIP Jr. VIP Premium Member

    Joined:
    May 12, 2010
    Messages:
    1,027
    Likes Received:
    859
    or record a macro in notepad++
     
  6. jbarrett

    jbarrett Registered Member

    Joined:
    Jul 21, 2011
    Messages:
    98
    Likes Received:
    40
    thanks artizhay that was exactly what I was looking for
     
  7. HostStage

    HostStage Jr. VIP Jr. VIP Premium Member UnGagged Attendee

    Joined:
    May 20, 2010
    Messages:
    1,770
    Likes Received:
    1,729
    Occupation:
    BHW - CEO of Webhosting Company
    Location:
    BWH from France
    Home Page:
    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
     
  8. mpulse

    mpulse Regular Member

    Joined:
    May 27, 2009
    Messages:
    292
    Likes Received:
    40
    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..
     
  9. randolph60

    randolph60 Junior Member

    Joined:
    May 13, 2011
    Messages:
    191
    Likes Received:
    48
    Do you have PHP experience?

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


    Randolph