How can I replace a particular line of text in file using php?
I don’t know the line number. I want to replace a line containing a particular word.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One approach that you can use on smaller files that can fit into your memory twice:
A quick note, PHP > 5.3.0 supports lambda functions so you can remove the named function declaration and shorten the map to:
You could theoretically make this a single (harder to follow) php statement:
Another (less memory intensive) approach that you should use for larger files: