I want to edit a file which extension is .doc This file contains some keywords such as:
<<Customer>>
<<DateStart>>
ecc.
Now I want to read the content of the file, edit it and then put it in new word.
I try in this way:
header ("Content-Type: application/msword; ");
header ("Content-Disposition: attachment; filename=new.doc");
$filename='a.doc';
$key = "«Customer»";
$fc=file($filename);
$f=fopen("'C:\Users\Ciro\Desktop\new.doc","w");
foreach($fc as $line){
if (strpos($line,$key))
$line=str_replace($key,"some new text",$line);
file_put_contents($f,$line);
}
fclose($f);
fclose($fc);
How can I fix it?