-1
I’m trying to read a file that comes from a form. When I send it to the Controller, I have to read the file and look for a line, if it exists, add a line right below.
Doubts:
1- I can find the phrase in the file, but I can’t add a line right below.
public function adiciona(Request $request){
/*
* O campo do form com o arquivo tinha o atributo name="file".
*/
$file = $request->file('file');
$searchthis = "|C190|000|6102|12,00|36702,99|36702,99|4404,36|0,00|0,00|0,00|0,00||";
$matches = array();
$handle = fopen($file, "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle);
if (strpos($buffer, $searchthis) !== FALSE) {
//$matches[] = $buffer;
}
}
fclose($handle);
}
//mostra os resultados:
print_r($matches);
// Faça qualquer coisa com o arquivo enviado...
}
Already tried to skip the line with PHP_EOL?
– Assis Duarte
I already managed to get the line I wanted, what is missing is to compare these two strings, to see if it exists in the file
– Enderson Cesar