This file is performing its function perfectly, but it is returning some errors and I would like to correct them. I need to know if I have to use fopen
and file_get_contents
because I can not undo any.
# /pasta/copy.php
<?php
$original = fopen('/pasta/copy.txt','r+');
$ip = fopen('/pasta/origin.txt','r');
$ip = file_get_contents('/pasta/origin.txt','r');
$copia = fopen('/pasta/ok.txt','w+');
if ($original) {
while(true) {
$linha = fgets($original);
if ($linha==null) break;
if(preg_match("/ASSunto/", $linha)) {
$string .= str_replace("ASSunto", $ip, $linha);
} else {
$string.= $linha; #**Linha 13**
}
}
rewind($copia);
ftruncate($copia, 0);
fwrite($copia, $string);
fclose($original);
fclose($copia);
fclose($ip); #**Linha 21**
}
?>
And the errors are as follows:
PHP Notice: Undefined variable: string in /pasta/copy.php on line 13
PHP Warning: fclose() expects parameter 1 to be resource, string given in /pasta/copy.php on line 21
The file copy.txt
.
# /pasta/copy.txt
Assunto para primeira linha
ASSunto
The file origin.txt
.
# /pasta/origin.txt
Assunto para segunda linha
The ok.txt
file looks like this.
# /pasta/ok.txt
Assunto para primeira linha
Assunto para segunda linha