There is a form with two inputs - the initial value and the replaced one, the form sends GET to the replace.php file
<?php $text = $_GET['mac1']; // Искомая строка $retext = $_GET['mac2']; // Строка замены $files = array( "v301.conf", "v302.conf", "v303.conf", "v304.conf", "v305.conf", "v306.conf", "v307.conf", "v308.conf", "v309.conf", "v310.conf", "v311.conf", "v312.conf", "v313.conf" ); // Массив файлов, в которых искать и заменять if($text !== "" && $retext !== ""){ // Если исходный и заменяемый тексты не пустые foreach($files as $f){ // получаем имена файлов $filename = $f; $file = file_get_contents($filename); // открываем каждый файл $file = str_replace($text, $retext, $file); // заменяем текст file_put_contents($filename, $file); // перезаписываем файл echo "Значение в файле ".$f." заменено <br>"; } } else { echo "Параметры для замены не найдены!"; } ?> When replacing text, even if it is not in some of the files, echo works, and the text is replaced in this file ...
Tell me, please, how competently to display the alert only for those files in which the value has been changed?