Answer the question
In order to leave comments, you need to log in
PHP str_replace not working after edit??
Hello everyone, I've got this problem.
There is php 7 installed on ubuntu libapache2modphp7
There are 3 files
delete.php
deleteexample.php
deletetext.php
PHP reads the deleteexample.php file, then creates a unique deletetext.php for each page and writes what was read into it, after that, written to deletetext.php also writes (does not overwrite but adds) to delete.php
And so delete.php is the repository of all deletetext.php
In the repository, the str_replace function is used that reads deletetext.php and looks for these lines in delete.php itself, if it finds it deletes them from there, the problem now that .
When creating a file via file_put_contents() deletetext.php after, if you edit delete.php , then when you click on the button, the script crashes and str_replace in delete.php refuses to work, but if you create these 2 files manually and then edit both, then everything works fine. the conclusion is that PHP and Apache are doing something clever when creating a file, and I just can't figure out what.
Can anyone help, I would be grateful. Here is the code.
delete.php
<?php
$selftext = 'deletetext39.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 "/";
}
$selftext = 'deletetext39.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 "/";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question