Zastąp ciąg w pliku tekstowym za pomocą PHP
Muszę otworzyć plik tekstowy i zastąpić ciąg. potrzebuję tego
Old String: <span id="$msgid" style="display: block;">
New String: <span id="$msgid" style="display: none;">
To jest to, co mam do tej pory, ale nie widzę żadnych zmian w pliku tekstowym oprócz dodatkowych białych spacji.
$msgid = $_GET['msgid'];
$oldMessage = "";
$deletedFormat = "";
// Read the entire string
$str = implode("\n", file('msghistory.txt'));
$fp = fopen('msghistory.txt', 'w');
// Replace something in the file string - this is a VERY simple example
$str = str_replace("$oldMessage", "$deletedFormat", $str);
fwrite($fp, $str, strlen($str));
fclose($fp);
Jak mogę to zrobić?