Alter many files, all with same variable in them

Discussion in 'PHP' started by woocha, Jan 17, 2008.

  1. #1
    I have 100's of files that access a field in a mySQL DataBase. I had to change the field name and now I have to update 100's of files. The files read:
    $sql = 'SELECT user_id, username, user_colour, user_birthday FROM '
    Code (markup):
    I need it to now read:
    $sql = 'SELECT id, nick, user_colour, user_birthday FROM '
    Code (markup):
    I know I could go through all files and execute a replace 'user_id' with 'id', but that would take forever. Does anyone know a program to do this easier?
     
    woocha, Jan 17, 2008 IP
  2. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Homesite has an extended replace function which will go through files and sub directories doing a search and replace.
     
    Gawk, Jan 17, 2008 IP
  3. woocha

    woocha Peon

    Messages:
    107
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the tip, but do you know of an open source version, that won't set me back a couple of hundred bucks?
     
    woocha, Jan 17, 2008 IP
  4. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Doing a Google I found this: http://www.orbit.org/replace/

    No idea what it is like but it is free!

    I'll leave the rest of the Googling to you ;)
     
    Gawk, Jan 17, 2008 IP
  5. woocha

    woocha Peon

    Messages:
    107
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks :)
    I appreciate the help!
     
    woocha, Jan 17, 2008 IP
  6. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Eclipse (eclipse.org) does search and replace across files. With PDT (based on Eclipse, eclipse.org/pdt ), you have an entire PHP development environment.

    The biggest question is this, though: why are you changing 100s of instances of one line, to 100s of instances of another line, when in the future you're probably going to have to do the same?

    You need to pull that string out into a variable at least... so that next time you need to change it you only have to change it in one spot.
     
    TwistMyArm, Jan 17, 2008 IP
  7. woocha

    woocha Peon

    Messages:
    107
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hey that sounds cool, how would I start to do that?
     
    woocha, Jan 17, 2008 IP
  8. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If you want to make the change from the unix command line, the program you need is 'sed'.
     
    SmallPotatoes, Jan 17, 2008 IP
  9. webwurks

    webwurks Well-Known Member

    Messages:
    126
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #9
    Here's a link to a couple of methods to do what you are asking:

    kb.iu.edu/data/afrk.html
     
    webwurks, Jan 17, 2008 IP
  10. woocha

    woocha Peon

    Messages:
    107
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    SWEET !!
    Thanks
     
    woocha, Jan 17, 2008 IP