Hello Kelly, ummmm I don't think there is any lasting value or time saving in changing bad code, instead, my suggestion is to throw out the "badly written" code altogether and start with something else you can actually work with. ... but if you're going to keep it: Following is a description of how to replace with constants that may be univerally applied throughout your code, and changed in one place. This is pretty much a universal practise in apps which are moved from site to site, it sounds like you need it: In changing websites you need a way to identify: a. the changed absolute file path b. the changed domain url This may be achieved a number of ways. One way is: a. create a constant called ABSOLUTE_FILE_PATH b. create a constant called DOMAIN_URL define("ABSOLUTE_FILE_PATH", "/public_html/"); define("DOMAIN_URL", "http://domain.com/"); Save the constants in a file called config.php Include config.php in every file that needs it Invoke a path or url by using your new constants example include_once( "config.php" ); // bring in the constants include( ABSOLUTE_FILE_PATH . "subfolder/" ); // use a path echo"<img src='" . DOMAIN_URL . "images/my_image.png'>"; // use a url This leaves the mysql connection stuff: do the same thing Put the connection data into config.php as constants: define("DBNAME", "enter_a_value_here" ); define("DBUSERNAME", "enter_a_value_here" ); define("DBPASSWORD", "enter_a_value_here" ); define("DBSERVERHOST", "enter_a_value_here" ); // sometimes localhost Include config.php (top of page) wherever you use database connects Replace your db connect code with your new constants Yes its a lot of work, but so is moving websites. When you're done you can move the code anywhere by changing one file. Sincerely, Rob http://phpyellow.com === Kelly wrote; >Date: Fri, 8 Jun 2007 19:42:10 -0600 >From: "Kelly Jones" <kelly.terry.jones@xxxxxxxxx> >To: php-general@xxxxxxxxxxxxx >Subject: Intercepting fopen, mysql_connect, and similar functions for >migration >I'm migrating a website from one server to another, and my file paths >and dbs have changed. >For example /a/b/c/foo.txt on the old machine is at /x/y/z/foo.txt on >the new machine. The MySQL db "foo" on the old machine is "bar" on the >new machine. > >Can I intercept fopen() and mysql_connect() so that when PHP does >fopen("/a/b/c/foo.txt"), I magically (using Zend functions or method >overloading or anything else) convert it at runtime to >fopen("/x/y/z/foo.txt"). > >Same thing so that mysql_connect("foo") becomes mysql_connect("bar"). > >The code is badly written: doing a search/replace in the code wouldn't >really work. I really want to "hook" fopen()/mysql_connect() and >similar commands so I can tweak their args before they actually >execute. Is there any hope? > >Sort of like an LD_PRELOAD for PHP? > >-- >We're just a Bunch Of Regular Guys, a collective group that's trying >to understand and assimilate technology. We feel that resistance to >new ideas and technology is unwise and ultimately futile. === -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php