[PHP-DB] Manioulating a Flat File

2002-10-18 Thread Davon

Hi:

I am new to this list.

Maybe this has been covered here already several time, and if it has I apologize. I 
tried searching, but it yielded nothing. 

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()? 

Thanks very much for your help!

dkmb



-
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos,  more
faith.yahoo.com


Re: [PHP-DB] Manioulating a Flat File

2002-10-18 Thread 1LT John W. Holmes
 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