Re: string replace in files

From: Date: Fri, 30 Apr 2004 17:57:27 +0000
Subject: Re: string replace in files
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-185069@lists.php.net to get a copy of this message
From: "Steve Buehler" <steve@ibapp.com> > Thank you so much for this. I was thinking of it all wrong when > doing this. I have a couple of other questions to go along with this. > 1. How would I change this to do a recursive search for the .php files > instead of just the *.php or */*.php in the glob? Make a recursive function and use the opendir() / readdir() functions. Use is_dir() to see if the file is a directory, and if so, call the function again passing the new directory. If it's not, grab the last four characters looking for ".php" to see if you should open/replace/rewrite the file. > 2. I also have some dns zone files that I was going to modify this script > to replace some information in them. What it would have to do is to delete > all lines that have white space (could be a space or a tab) NS more white > space and then add specific lines that I want in place of the deleted lines. > 2.a. There will normally be between 2 and 4 lines that I want > deleted and 2 to replace them. Same method. You'd probably want to use a regular expression to get rid of the lines and insert the replacement text. ---John Holmes...

« previous php.general (#185069) next »