Jump to content

Alter many files, all with same variable in them

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
woocha

woocha

    Newbie

  • Members
  • Pip
  • 2 posts
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 '
I need it to now read:
$sql = 'SELECT id, nick, user_colour, user_birthday FROM '

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?

#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Some text-editors has this function as a built-in feature. You should check out if your text-editor has it. You'll probably find the feature under the name of "replace," or something similar.

#3
woocha

woocha

    Newbie

  • Members
  • Pip
  • 2 posts
Thanks man...I'll check my editor:)

#4
ETbyrne

ETbyrne

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
You could use PHP if you copied the source code to a normal text file first:
<?php

$content = file_get_contents("myscript.txt"); // not the PHP file

$content = str_replace("user_id", "id", $content)
// And so on and so forth...

// Then you would have to have it write the new code in to the
// text file
?>

My website > www.evanbot.com