I'm fairly sure you could use a pointer, the file opperations in PHP seem to be very closly linked to those in C...
Failing that you could read the entire string to a variable then use the split() function to remove the dat ayou wanted to keep/put bits in the middle of.
for instance if you wanted to insert a new row into the top of a table in an HTML document, you could do it like this
-----------------------
<?php
//open file for reading
$file = "/path/to/file.txt";
$link = fopen($file, "r");
//read file to string
$contents = fread($link, filesize($file));
fclose($link);
//get size of string
for($line=0;$line<sizeof($contents);$line++)
//split the start of the file after the table tag
//the first half goes to a[0] the second half goes to a[1]
$a = split("<table>", $contents[$line]);
$b = "your_stuff_you_want_to_insert "
//not sure if this string is consturcted right
//if it were asp it be text = a[]0 & yourstring & a[1]
$text = "$a[0] $b $a[1]"
//open file destructive open
$file = "/path/to/file.txt";
$link = fopen($file, "w");
//write string to file
//not sure if this is correct
fwrite($link, $text));
fclose($link);
?>
-----------------------------------------------------
Again i'm sory I've not tested this code before posting it (got many many assignments due). You might have to look some ov the details about how to use functions over in the PHP manual.
But I hoped this suggestion was beter than complete silence!