Overwrite Line in File with PHP

后端 未结 7 2048
天命终不由人
天命终不由人 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:55

    I'd most likely do what Jeremy suggested, but just for an alternate way to do it here is another solution. This has not been tested or used and is for *nix systems.

    $cmd = "grep '@parsethis' " . $filename;
    $output = system($cmd, $result);
    $lines = explode("\n", $result);
    // Read the entire file as a string
    // Do a str_repalce for each item in $lines with ""
    

提交回复
热议问题