You can use the php substr function as you read the txt file, like this:
$origem = 'origem.txt';
$destino = 'destino.txt';
$arqOri = fopen($origem, 'r'); // Abre o arquivo de origem para leitura
$arqDes = fopen($destino, 'w'); // Cria o arquivo como destino
while (!feof($arqOri)){
$str = fread($arqOri);
$strNovo = substr($str, 0, 9) . ',' .
substr($str, 9, 7) . ',' .
substr($str, 15, 12);
fwrite($arqDes, $strNovo);
}
fclose($arqOri);
fclose($arqDes);
This way you are opening a file, reading line by line and adjusting the information, writing to another file.
In this case, if the destination file exists it will be overwritten with the new content.
What is the criterion for the insertion of commas?
– Luiz Augusto
first comma after 9 characters, second comma after 1 character, third comma after 4 characters
– Antônio
Will always follow this padaroo to all the lines
– Antônio
which system? Linux or windows?
– Luiz Augusto
I am using windows
– Antônio