Here's what I'd like to know: Is there a PHP function for easily finding
and removing a line from a flat file of data. And, if not, is there a way
to remove a line (or lines) after finding them using fget()?
Easy way to do this is with file(). It'll read the entire file into an
array, with each array element being a line of the file. Use array_search()
to find the line you're looking for, then unset() that element.
//line to look for
$search = ...;
$file = file(file.txt);
$key = array_search($search,$file);
if($key === FALSE)
{ echo line not found; }
else
{ unset($file[$key]); }
//write corrected file back to disk
$fp = fopen(file.txt);
fwrite($fp,implode(\n,$file);
fclose($fp);
Adapt to your needs...
---John Holmes...
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php