Find - n - replace
| From: | John Starkey | Date: | Wed, 23 May 2001 03:44:38 +0000 |
| Subject: | Find - n - replace | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-9552@lists.php.net to get a copy of this message | ||
Hello all.
I'm trying to set up a quick find and replace script. It's finding, and
it's pasting what I want, but on the following line, I can't get it to
replace. Can anyone help?
#!/usr/local/bin/php -q
<?php
$fp = fopen( "./somefile.html","r+");
while ( !feof( $fp ) ) {
$line = fgets( $fp, 4096 );
if ( eregi( "<td", $line ) ) {
if ( eregi( "4[0-9]{2}", $line ) ) {
$liner = eregi_replace( "4[0-9]{2}", "470", $line );
fputs( $fp, $liner, strlen( $liner ) );
}
}
}
fclose( $fp );
?>
Can anyone tell me how I can back the fput up one line so it overwrites
the result of the search?
Thanks,
John