Hello everyone, there are 3 files
testcrea.php // reads testexample.php and writes to testtext.php and test.php
test.php // reads testtext.php if there is a match in itself, replaces with an empty string
testexample.php // template with specified text

The problem is that everything works, but it is worth going to test.php and adding
for example echo 'ok'; , and test.php stops working at start-up as if str_replace is not even in the code, although I don’t touch the search and replace line at all.
Here is the code

testexample.txt

 $selftext = 'testtext.php'; $selffile = 'test.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)) { echo "succes self remove"; } 

testcrea.txt

 <?php $delete = 'test.php'; $exampledel = 'testexample.txt'; $exampled = file_get_contents($exampledel); $fulldeletetext = 'testtext1.php'; // Delete $delold1 = array("testtext"); $delnew1 = array("testtext1"); $delphrase1 = str_replace($delold1, $delnew1, $exampled); if(file_put_contents($delete, PHP_EOL . $delphrase1, FILE_APPEND)) { echo "succesdelete\n"; } if(file_put_contents($fulldeletetext, $delphrase1)) { //запись в deletetext.php (тогоже контента что и в delete) echo "succesdeletetext\n"; } 

test.php (empty, waiting to be written to it, to check if there is a similar line in testtext after launching, if so, remove this line from yourself

 <?php /* ------ BEGIN SCRIPT WORKING -----------*/ 
  • Yes, only I found a specific problem in the script, so I wrote a new one - hovdev
  • Well, everything is clear, you add echo 'ok' and there is no coincidence on the salb. Why do you need such a creepy algorithm? - Naumov
  • no, echo 'ok' I add up to the search / replace line itself, it shouldn’t do that - hovdev
  • Really not one php developer can not understand what's the problem? I have been sitting on this problem for 3 hours now .. - hovdev

1 answer 1

The problem was solved, it was dug so deep that it almost reached China, and the problem was in the extension of the .txt file, changed to .php and it worked normally an interesting situation or a bug with str_replace.