PHP read a large file line by line and string replace -


i'd read large file line line, perform string replacement , save changes file, iow rewriting 1 line @ time. there simple solution in php/ unix? easiest way came on mind write lines new file , replace old one, it's not elegant.

i think there're 2 option

  1. use memory

read, replace store replaced string memory, once done, overwrite source file.

  1. use tmp file

read & replace string write every line tmp file, once done, replace original file tmp file

the #1 more effective bcuz io expensive, use if have vast memory or processing file not big.

the #2 bit slow quite stable on large file.

of course, may combine both way writing replaced string by chunk of lines file (instead of by line)

there're simplest, elegant ways can think out.

please correct me if wrong.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -