Cool thanks, that probably will make my code execute a decent bit faster (as the file gets larger).
But the array_search function never works for me (don't know why, I know exactly what I'm searching for and that it is there), so I made my own function.. //Find and return first occurance of a string ("$Find") in any line of $LineArray function FindKey($LineArray, $Find) { foreach($LineArray as $key => $value) { if (ereg($Find, $value)) return $key; } return FALSE; } // END OF FindKey(...); I think this combined with your code should help me a lot, thanks a ton. "Analysis & Solutions" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > On Thu, Jul 11, 2002 at 02:11:30PM +1000, Martin Towell wrote: > >> From: Chris Earle [mailto:[EMAIL PROTECTED]] > >> > >> I was wondering if there was a function that would allow me to "jump" > >> to a certain line if a file and then write from there? I'm searching > >> php.net without any luck :(. > > > > I dodn't know of any single function that does what you want, but you can do > > this: > > > > $contents = file($filename); // each line has it's own array position > > $contents[$line] = $newline; > > That's nice, except you could start overwriting existing data. > > If you're only interested in appending to the end of a file, then use > $fp = fopen('filename', 'a+'); > and fputs() all you want. > > But, if you want to stick stuff into the middle... > > # Real process uses file(), > # but for test, set Content manually. > $Content[] = 'The start of the content array.'; > $Content[] = 'Some more stuff.'; > $Content[] = 'And yet more stuff.'; > > $Location = array_search('Some more stuff.', $Content); > > $New[] = 'Why, here is some new stuff'; > > $Final = array_merge( > array_slice($Content, 0, $Location + 1), > $New, > array_slice($Content, 0 - (count($Content) - $Location - 1)) > ); > > # In your process, you'll really want to insert > # implode('', $Final) into the file with fputs(), > # but, hey, this is a demonstration. > print_r($Final); > > > --Dan > > -- > PHP classes that make web design easier > SQL Solution | Layout Solution | Form Solution > sqlsolution.info | layoutsolution.info | formsolution.info > T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y > 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php