Re: file management
| From: | Gerard Samuel | Date: | Fri, 07 Sep 2001 21:46:51 +0000 |
| Subject: | Re: file management | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-66488@lists.php.net to get a copy of this message | ||
Sterling, your example looks doable, Ill report back when Im done with these other functions. Thanks
Sterling Hughes wrote:
On Fri, 7 Sep 2001, Gerard Samuel wrote:Can a file be truncated from the beginning, and by x amount of lines?? ThanksTruncated from the beginning? Do you mean truncate the file by X lines, starting from the first position in the file, well, yeah:<?php $fp = fopen("filename", "r+");// Start counting from 0, set to one, if you want to start counting // from 1 $count = 0;while (!@feof($fp)) { // Not used, but unless your line lengths are longer than // 4K, this will effectively skip over a line $line = fgets($fp, 4096);if (++$count == $line_number_you_want) { ftruncate($fp, ftell($fp)); } }fclose($fp); ?>Please note the above is devoid of error checking :)-Sterling