on 29/11/02 7:06 PM, Jeff RingRose ([EMAIL PROTECTED]) wrote:

> Justin,
> Option b. delete all AFTER "foo", I.E. truncate the file directly after
> "foo". Leaving "foo" and all the data before "foo" untouched.

And what happens if there are more than one occurrence of "foo"?  I assume
you mean the first occurrence.

And what happens if "foo" is found within another word, like "aafooaa"...
this example assumes this doesn't matter... it's looking for 'foo', not '
foo '.

One of way is to read the file into a variable, split the var on "foo", and
rewrite the file out.

$split = 'foo';
$file = 'dummyfiles/01-04-29.php';

// get file contents
$fd = fopen ($file, "r");
$mytext = fread ($fd, filesize($file));
fclose ($fd);

// split it on $split, append $split to first chunk
list($prefix,$suffix) = split($split,$mytext);
$newtext = $prefix.$split;

// write to file
$fp = fopen($file, 'w');
fwrite($fp, $newtext);

1. Totally untested code, but most of it was lifted out of the manual in
some way or another.

2. Permissions of the file to be read/written will need to be correct

3. I've included no error reporting or correct checking... you'll need to
add this yourself

Season to taste...

Justin French
Web Development & 
Graphic Design

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to