本文介紹了用 PHP 覆蓋文件中的行的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
覆蓋文件中特定行的最佳方法是什么?我基本上想在文件中搜索字符串@parsethis"并用其他內(nèi)容覆蓋該行的其余部分.
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(),在行數(shù)組中搜索您的字符串并編輯該行,然后 implode() 將數(shù)組重新組合在一起并將 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.
這篇關(guān)于用 PHP 覆蓋文件中的行的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!