Back in data txt

Asked

Viewed 32 times

1

i have a table of my blog called noticas, in this table news I have the fields, id, title, text, author, date

would like to create a button where clicking on it creates a file . txt with all the information coming from my database ex:

id: 1
titulo: titulo da noticia 1
texto: texto da noticia 1
autor: autor do post 1
data: data do post 1

id: 2
titulo: titulo da noticia 2
texto: texto da noticia 2
autor: autor do post 2
data: data do post 2


id: 3
titulo: titulo da noticia 3
texto: texto da noticia 3
autor: autor do post 3
data: data do post 3

and so on and so on.. taking all the DB data how can I be doing this ?

  • Opens the file with the fopen(), goes through the records writing in the archive, with fwrite(), and in the end closes it with fclose(). Have you tried anything?

1 answer

0

Example

Do the query in the database, and have it printed with this function:

function gravar($texto){
    //Variável arquivo armazena o nome e extensão do arquivo.
    $arquivo = "nomedoarquivo.txt";
    //Variável $fp armazena a conexão com o arquivo e o tipo de ação.
    $fp = fopen($arquivo, "a+");
    //Escreve no arquivo aberto.
    fwrite($fp, $texto . ";");
    //Fecha o arquivo.
    fclose($fp);
}

In the example, you are separating by ";", there is the criterion to use line break, etc. Basically how to print a table/list.


References

Write and read txt file

Browser other questions tagged

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