本文介紹了用 PHP 覆蓋文件中的行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
覆蓋文件中特定行的最佳方法是什么?我基本上想在文件中搜索字符串@parsethis"并用其他內容覆蓋該行的其余部分.
What is the best way to overwrite a specific line in a file? I basically want to search a file for the string '@parsethis' and overwrite the rest of that line with something else.
推薦答案
如果文件不是太大,最好的方法可能是將文件讀入帶有 file(),在行數組中搜索您的字符串并編輯該行,然后 implode() 將數組重新組合在一起并將 fwrite() 返回到文件.
If the file isn't too big, the best way would probably be to read the file into an array of lines with file(), search through the array of lines for your string and edit that line, then implode() the array back together and fwrite() it back to the file.
這篇關于用 PHP 覆蓋文件中的行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!