Re: Search and replace a String in a file.

From: Date: Thu, 24 Jun 2004 18:26:01 +0000
Subject: Re: Search and replace a String in a file.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-188986@lists.php.net to get a copy of this message
You need to do: $snr = new File_SearchReplace(...); On Thu, 24 Jun 2004 13:52:55 -0400, Eric L. Sammons <esammons@vt.edu> wrote: > > First let me thank you for pointing me to PEAR. Now for the problem. Here is > my code: > > <?php > require_once 'File/SearchReplace.php'; > > $serverName = "pxt010"; > $dir = "/home/ossadmin/"; > $file = "server-info.temp"; > > $nfile = "server-$serverName.spec"; > > $ignoreline = array("%", "#"); > > system("sudo /bin/cp $dir$file $dir$nfile", $return); > if (file_exists($dir.$nfile)) { > print "<h3>File exists.</h3>"; > $snr = File_SearchReplace("server-temp", > "server-$serverName", $nfile, > $dir, false, $ignoreline); > $snr -> doSearch(); > } else { > print "<h3>File does not Exist</h3>"; > } > > ?> > > Here is my output: > > File exists. > > Fatal error: Call to undefined function: file_searchreplace() in > /home/els/SrvrBuild/rpl.php on line 15 > > I have tried both include ... and require_once ... with the same result. > > Help? > > Thank you! > >===== Original Message From Justin Patrin <papercrane@gmail.com> ===== > > > >There's a PEAR package for just this. :-) > >http://pear.php.net/package/File_SearchReplace > > > >On Thu, 24 Jun 2004 12:58:08 -0400, Eric L. Sammons <esammons@vt.edu> wrote: > >> > >> Being new to PHP this task seems to be little out of my reach right now. I > >> wonder if anyone could tell me how, as I read a file, line by line, search > for > >> and then replace a given string? > >> > >> The lines in the file will appear as such: > >> > >> Summary: Some Summary > >> Name: Some-Name > >> Version: x.x > >> . > >> . > >> . > >> > >> Basically I will open the file, read its lines one by one and I want to > >> replace Some-Name with Some-other-Name. > >> > >> Thank you! > >> > >> -- > >> PHP General Mailing List (http://www.php.net/) > >> To unsubscribe, visit: http://www.php.net/unsub.php > >> > >> > > > > > > > > > >-- > >paperCrane --Justin Patrin-- > > > >-- > >PHP General Mailing List (http://www.php.net/) > >To unsubscribe, visit: http://www.php.net/unsub.php > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- paperCrane --Justin Patrin--

« previous php.general (#188986) next »