fletcher
fletcher

Reputation: 58

Write Database table to txt file PHP

I need some help with this problem.

I'm work with laravel, and I got the select which look like this:

$table = Onlineszallas::all()->toArray();

I wanna write this query to a TXT file with latin2 file charset, every row in the table, in new line, strings separated by ; and every row end with;

I tried the fputcsv() method but if I open the txt file I found some string which contain space between to apostrophe like the name row. "George Michael"

I need some help with file_put_contents() or any other method which can solve my problem!

Many thanks!

Upvotes: 2

Views: 2158

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163898

You can use Storage facade. Create a file:

use Illuminate\Support\Facades\Storage;
Storage::put('file.txt', $contents);

Add text content to a file:

Storage::append('file.txt', $someOtherContent);

But I would recomment you to store data as JSON:

$table = Onlineszallas::all()->toJson();

In this case you'll be able to easily import the data in any system.

Upvotes: 1

Related Questions