Overwrite Line in File with PHP

后端 未结 7 2034
天命终不由人
天命终不由人 2020-11-30 12:37

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 somethi

7条回答
  •  情书的邮戳
    2020-11-30 12:45

    or if your file isn't too big:

    $sample = file_get_contents('sample');
    $parsed =preg_replace('#@parsethis.*#', 'REPLACE TO END OF LINE', $sample);
    

    You'll have to choose delimiters '#' that aren't present in the file though.

提交回复
热议问题