Welcome Guest, Not a member yet? Register   Sign In
How to? word-wrapp with write_file() (txt, file_helper)
#1

[eluser]Jan_1[/eluser]
I'm working with XAMPP on localhost and do create and update textfiles. But I don't get a word-wrap with \n oder \r\n. What can i do to write line for line in a txt-file?

Code:
// get some ids from the formular
$export_id = $this->input->post('export_id');
// headline in new textfile
$headline   =   '"zip";"city";"country"'.'\n';
// create new textfile with a headline
        write_file('file_path/example.txt', $headline);
// for every id from formular get data from a db-table
        foreach($export_id as $id)
        {
            $this->db->where('export_id', $id);
            $query  =   $this->db->get('persons');
            if($query->num_rows()>0)
                {
                    $person =   $query->row();
// creating the next line for the textfile and write it in the textfile
                    $line   =   $person->export_zip.", ".
                                $person->export_city.", ".
                                $person->export_country.'\n';
                    write_file('file_path/example.txt', $line, 'a');
                }
It works, but all the content is in one line. What can I do better?
#2

[eluser]CroNiX[/eluser]
Try putting your newline string within double quotes instead of single (which means literal...you don't literally want \n appearing as text - you want it to be evaluated as a new line character).

Code:
$person->export_country . "\n";




Theme © iAndrew 2016 - Forum software by © MyBB