CodeIgniter Forums
How to? word-wrapp with write_file() (txt, file_helper) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to? word-wrapp with write_file() (txt, file_helper) (/showthread.php?tid=57051)



How to? word-wrapp with write_file() (txt, file_helper) - El Forum - 02-11-2013

[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?


How to? word-wrapp with write_file() (txt, file_helper) - El Forum - 02-11-2013

[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";