Code: Select all
$filename = 'quote.txt';
$handle = fopen($filename,'r+');
$file = fread($handle, filesize($filename));
$replace = str_replace('meatball','little number',$file);
fwrite($replace,$file);
fclose($handle);So, as I understand it, once the script is done with $replace, it's holding the whole file, with 'meatball' changed to 'little number', correct?
If so, that's all well and good. But suppose quote.txt is a thousand or so lines long. I probably don't want to be kicking huge chunks of data around in variables like that, do I?
My question, then (I guess!), is: what's the best way to efficiently pick the word 'meatball' out of 1000+ lines of a file, and surgically replace it with 'little number'?