"replace string in text file using php" Code Answer

2

Does this work:

$msgid = $_GET['msgid'];

$oldMessage = '';

$deletedFormat = '';

//read the entire string
$str=file_get_contents('msghistory.txt');

//replace something in the file string - this is a VERY simple example
$str=str_replace($oldMessage, $deletedFormat,$str);

//write the entire string
file_put_contents('msghistory.txt', $str);
By 9900tw-f8dc908ff1ec on December 15 2022

Answers related to “replace string in text file using php”

Only authorized users can answer the search term. Please sign in first, or register a free account.