I need to go through the data of several txt, take specific data and generate a csv

0

I'm already browsing the files and accessing the data, but I need to get what's after the following line:

Initial P.A.C. () P.A.C. () Match amount due 3a. part contemplation due due payment effected Balance Sopave

to the top line of this data: (*) Proposal for Admission to Consortium

I'm thinking of doing with regex or using an if ...

This is my code:

<?php

//PERCORRENDO OS ARQUIVOS TXT DO LIVRO 02
$path = "/guardiao/files/juridico/Livro 02 - Medio - Ok";
$diretorio = dir($path);
echo '<pre>';
while($arquivo = $diretorio -> read()){
if ($arquivo == '.' || $arquivo == '..') continue;
$ext = array_reverse(explode(".", $arquivo))[0];

if($ext == 'txt'){
    //echo $arquivo.'<br/>';
    $conteudo = file_get_contents($path.'/'.$arquivo);
    //SUBSTITUIR ESPEÇO EM BRANCO POR ;
    $subst_espaço = preg_replace("/( )+/", ';', $conteudo);
    //TRANSFORMAR CADA LINHA EM UM ARRAY
    $linhas = explode("\n", $subst_espaço);
    foreach ($linhas as $linha) {
         echo $linha;
        $linha_dados = 1;
        $linha_titulo = 'a';
        if ($linha) {

        }
    }
    // $linhas = count($ler);
    //PEGAR SOMENTE OS DADOS APÓS A LINHA QUE POSSUIR ; E UM NUMERO
    // var_dump($ler);
     //print_r($linha);
    // exit();

}
// print_r($ext.'<br/>');
// echo $arquivo."<br />";
}
$diretorio -> close();

?>
  

This is one of the files:

and

&

Annex VI

Rodobens Administração e Promoções Ltda.

Commissions on sales of consortium quotas - Real Estate Base date: May 22, 2002

In Reais % of

% of commission _ Commission Commission Commission Total Balance Reimbursement Commission Credit number due due to spreadsheet Initial status due in due commission commissions Amount spreadsheet Initial P.A.C. () P.A.C. () Match amount due 3a. installment due due paid payment Balance Sopave 150,620 25,000.00 2.62% 1.42% Active 655.00 125.00 0.00 0.00 780.00 655.00 0.00 125.00 (300.00) 150,619 25,000.00 2.62% 1.42% Active 655.00 125.00 0.00 0.00 780.00 655.00 0.00 125.00 (300.00) 150,610 25,000.00 2.62% 1.42% Active 655.00 125.00 0.00 0.00 780.00 780.00 0.00 0.00 355.00 150.607 80.000.00 2.62% 1.42% Active 2.096.00 400.00 0.00 0.00 2.496.00 2.496.00 0.00 0.00 1.136.00 150.605 25.000.00 2.62% 1.42% Active 655.00 125.00 0.00 0.00 780.00 780.00 0.00 0.00 355.00 150,560 30,000.00 2.62% 1.42% Inactive 786.00 0.00 0.00 336.00 450.00 450.00 0.00 0.00 426.00 150,556 80,000.00 0.00% 1.42% Inactive 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.136.00 150,533 25,000.00 2.62% 1.42% Inactive 655.00 0.00 0.00 655.00 0.00 0.00 0.00 0.00 355.00 150,531 25,000.00 2.62% 1.42% Inactive 655.00 0.00 0.00 655.00 0.00 0.00 0.00 0.00 355.00 150,522 30,000.00 2.62% 1.42% Active 786.00 150.00 0.00 0.00 936.00 936.00 0.00 0.00 426.00 150.493 50.000.00 2.62% 1.42% Active 1.310.00 250.00 0.00 0.00 1.560.00 1.560.00 0.00 0.00 710.00 150,443 25,000.00 2.62% 1.42% Active 655.00 125.00 0.00 0.00 780.00 780.00 0.00 0.00 355.00 150,439 25,000.00 2.62% 1.42% Active 655.00 125.00 0.00 0.00 780.00 780.00 0.00 0.00 355.00 150,432 35,000.00 2.62% 1.42% Active 917.00 175.00 0.00 0.001.009.00 1.092.00 0.00 0.00.007.00 150,426 25,000.00 2.62% 3.12% Active 655.00 125.00 125.00 0.00 905.00 0.00 0.00 905.00 (125.00) 150,420 25,000.00 2.62% 2.62% Active 655.00 125.00 0.00 0.00 780.00 780.00 0.00 0.00 655.00 150.404 25,000.00 2.62% 1.42% Inactive 655.00 0.00 0.00 280.00 375.00 655.00 0.00 (280.00) (300.00) 150.403 25,000.00 2.62% 1.42% Inactive 655.00 0.00 0.00 280.00 375.00 655.00 0.00 (280.00) (300.00) 150.401 55.000.00 2.62% 1.42% Inactive 1.441.00 0.00 0.00 616.00 825.00 825.00 0.00 0.00 (660.00) 150,400 25,000.00 2.62% 1.42% Inactive 655.00 0.00 0.00 280.00 375.00 655.00 0.00 (280.00) (300.00) 150,397 25,000.00 2.62% 1.42% Inactive 655.00 0.00 0.00 280.00 375.00 655.00 0.00 (280.00) (200.00) 150,394 25,000.00 2.62% 1.42% Inactive 655.00 0.00 0.00 280.00 375.00 655.00 0.00 (280.06) (200.00) 150,392 25,000.00 2.62% 1.42% Inactive 655.00 0.00 0.00 280.00 375.00 655.00 0.00 (280.00) (300.00) 150,391 25,000.00 2.62% 1.42% Inactive 655.00 0.00 0.00 280.00 375.00 655.00 0.00 (280.00) (300.00) 150,388 25,000.00 2.62% 1.42% Inactive 655.00 0.00 0.00 280.00 375.00 655.00 0.00 (280.00) (300.00) (*) Proposal of Admission in Consortium (**) Constant cap in the September 2001 replacement report 1?

    
asked by anonymous 04.02.2018 / 00:27

1 answer

2
  

[...] I need to get what's after the following line:

     

Initial P.A.C. () P.A.C. () Quota sum due 3a. portion   contemplation due due paid Effect Balance

     

[...] to the top line of this data: (*) Proposal for Admission to Consortium

Since you have already determined a static start and end point, just place those points between the catch group with the . ken token that captures any character and a *? >, it will capture all the characters until the first occurrence of the (*) Proposta de Admissão em Consórcio sequence.

Then use this regex to capture the content you want:

P\.A\.C\.\(\) inicial P\.A\.C\. \(\) Sopave da cota devida 3a\. parcela contemplação devidas devidas pago efetivados Saldo Sopave(.*?)\(\*\) Proposta de Admissão em Consórcio

With it you can use the command preg_match_all() and preg_match() , after that you only put the result in a variable and write it in a csv as you mentioned in the title.

You can see an example of the regex running here.

Example preg_match () :

$subject = 'seu texto aqui';
$pattern='~P\.A\.C\.\(\) inicial P\.A\.C\. \(\) Sopave da cota devida 3a\. parcela contemplação devidas devidas pago efetivados Saldo Sopave(.*?)\(\*\) Proposta de Admissão em Consórcio~';
$success = preg_match($pattern, $subject, $match);
if ($success) {
    echo "Match: ".$match[1]."<br />";
}

Example preg_match_all () :

$subject = 'seu texto aqui';
$pattern='~P\.A\.C\.\(\) inicial P\.A\.C\. \(\) Sopave da cota devida 3a\. parcela contemplação devidas devidas pago efetivados Saldo Sopave(.*?)\(\*\) Proposta de Admissão em Consórcio~';
$hits = preg_match_all($regex,$airports,$matches,PREG_SET_ORDER); //hits é o vetor com seus matches
    
05.02.2018 / 12:46