
12-12-07, 03:37 PM
|
 |
Community Liaison
|
|
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
|
|
Here's a quick and dirty example that should do what you'd like:
PHP Code:
<?php
// The file $filePath = './file.txt';
// Grab file into an array, by lines $fileArr = file( $filePath );
// Remove desired line unset( $fileArr[3] ); // $fileArr[3] == line #4
// Put back with PHP4 $success = FALSE; if ( ( $fp = fopen( $filePath, 'w' ) ) !== FALSE ) { if ( flock( $fp, 2 ) ) // LOCK_EX { fwrite( $fp, implode( '', $fileArr ) ); flock( $fp, 3 ); // LOCK_UN $success = TRUE; } fclose( $fp ); }
/* // Or, put back with PHP5 $success = FALSE; if ( file_put_contents( $filePath, implode( '', $fileArr ), LOCK_EX ) ) { $success = TRUE; } */
?>
__________________
The toxic ZCE
Last edited by Keith; 12-12-07 at 03:44 PM.
|