Reputation: 27
$a = trim($allDataInSheet [$i]["A"]);
$b=trim($allDataInSheet [$i]["B"]);
/* copy the source file */
$fname = "edm.html";
copy("edm.html","hk/edm.html");
$fcopy="hk/edm.html";
/* read the duplicate file */
$fhandle = fopen($fcopy,"r");
$content = fread($fhandle,filesize($fcopy));
/* replace the string in the duplicate file */
$content = str_replace($a,$b, $content);
$fhandle = fopen($fcopy,"w");
fwrite($fhandle,$content);
fclose($fhandle);
Above code was not working properly,I dont want to replace the string inside the source file.I need to take the duplicate of the source file and change the strings.Thanks in advance.Pleaes help me to fix it..
Upvotes: 0
Views: 62
Reputation: 3864
I think this may be simpler if you just use file_get_contents
and file_put_contents
.
$fname = 'edm.html';
copy('edm.html', 'hk/edm.html');
$fcopy = 'hk/edm.html';
// read the file
$content = file_get_contents($fcopy);
// make the replacement
$content = str_replace($a, $b, $content);
// write the file
file_put_contents($fcopy, $content);
Also if you put
error_reporting(E_ALL);
ini_set('display_errors', 1);
at the start of your script you will make sure that you are seeing all PHP errors.
Upvotes: 1