txt file content display in php

Asked

Viewed 20 times

-1

Hello, I’m trying to read a txt file created with data entered by users of a site (name, email, company and phone) and I want to display the information inside the txt file using php.

My code so far is like this:

<? 
                    $arquivo = fopen('Log_Cadastro_de_ident.txt', 'r');

                    $dados = array();

                    while(!feof($arquivo)){

                        $dados[] = explode('*', $arquivo);
                        
                                          };

                    //fechamento do arquivo
                    fclose($arquivo); 
                ?>
                <div class="card-consultar-chamado">
                   <p class="identif"> <?= $dados[0] ?> </p>
                   <p class="identif_1"> <?= $dados[1] ?> </p>
                   <p class="identif_1"> <?= $dados[2] ?> </p>
                   <p class="identif_1"> <?= $dados[3] ?> </p>
                </div>

The problem is that when I run the code it passes me the following information on the screen:

inserir a descrição da imagem aqui

1 answer

0


It is missing the "fgets" to pick up the content of the line, try so:

<?php

$dados = array();

$arquivo = fopen('Log_Cadastro_de_ident.txt', 'r');
while (!feof($arquivo)) {
   $line = fgets($file_handle);
   $dados[] = explode('*', $line );
}
fclose($file_handle);

Note: If you send the text file, it is easier to propose a solution

  • It worked out dude, thank you so much!! Next time attach the text file

Browser other questions tagged

You are not signed in. Login or sign up in order to post.