Hello everyone, there is a script that reads a sample, searches for the same text in itself, finds and replaces it with an empty line.
Everything works with a bang, only now sometimes some bugs arise, I cannot understand what the problem is, if the script is not touched and not edited everything with a bang, but when, for example, I add some functions to it by hand, (Without touching the search and replace string itself), he refuses to remove information from himself on the model. The code is pretty big, but I'll post it, maybe I missed something.
$variable = $_POST['deleten']; //пост запрос на удаление текста $value = 'deleten'; //значение запроса на удаление $admfile = 'admintoursample.php'; //образец админки $pagefile = 'toursample.php'; //название страницы $contfile = 'content/contentsample.txt'; // контент с названием изображения $contfile2 = 'content/contentsample2.txt'; //контент2 $contback = 'content/contentsample2back.txt'; //backupконтента $contimage = file_get_contents($contfile); //читает название изображения if ($variable == $value) { //если значение совпадает с именем post запроса $admlist = 'adminpan.php'; //админ панель куда записывается $admcont = file_get_contents($admlist); //читаем $admstring = '<p><a href="admintoursample.php">toursample.php</a></p>'; $admcontold = array("$admstring"); //читаем строку из файла страницы если в админке есть такаяже строка заменяем ее на пустую строку "" $admcontnew = array(""); $admphrase = str_replace($admcontold, $admcontnew, $admcont); if(file_put_contents($admlist, $admphrase)) { echo "succes page\n"; } unlink($admfile); //удаляем ненужные файлы , так как удаляем страницу unlink($pagefile); unlink($contfile); unlink($contfile2); unlink($contback); unlink($contimage); echo "Successfuly removed"; $partext = 'resettext.txt'; // текстовый файл с php кодом $parfile = 'reset.php'; // главный файл куда записываются данные после создания страницы , и он их исполняет если понадобится , и при удалении сравнивает текст из 'resettext.txt' и у себя , если есть совпадения удаляет из себя строку которая совпала $parfilecont = file_get_contents($parfile); $partextcont = file_get_contents($partext); $parcontold = array($partextcont); $parcontnew = array(""); $parphrase = str_replace($parcontold, $parcontnew, $parfilecont); if(file_put_contents($parfile, $parphrase)) { unlink($partext); echo "succes reset remove"; } else { echo "/"; } $cretext = 'creatortext.txt'; //тоже самое что выше , только этот скрипт занят другой работой , но смысл один и тотже , поиск замена и удаление. $crefile = 'creator.php'; $crefilecont = file_get_contents($crefile); $cretextcont = file_get_contents($cretext); $crecontold = array($cretextcont); $crecontnew = array(""); $crephrase = str_replace($crecontold, $crecontnew, $crefilecont); if(file_put_contents($crefile, $crephrase)) { unlink($cretext); echo "succes creator remove"; } else { echo "/"; } $selftext = 'deletetext.php'; //тоже самое что и выше. $selffile = 'delete.php'; $selffilecont = file_get_contents($selffile); $selftextcont = file_get_contents($selftext); $selfcontold = array($selftextcont); $selfcontnew = array(""); $selfphrase = str_replace($selfcontold, $selfcontnew, $selffilecont); if(file_put_contents($selffile, $selfphrase)) { unlink($selftext); echo "succes self remove"; } } else { echo "/"; }