0

I'm having this simple php code to generate a text file with some data in lines.

$fileName = date('dmY').'.txt';
$handler = fopen('files/'.$fileName,'a+');
$exporteddata = date('dmY').PHP_EOL;
for ($x=0; $x<count($_POST['category']); $x++){
    if($_POST['category'][$x] > 0){
        $cat_data = $this->my_model->get_cat_data($_POST['category'][$x]);

        $exporteddata.=$cat_data[0]['cat_code'].';'.$_POST['count'][$x].PHP_EOL;

    }
}
fwrite($handler,$exporteddata);
fclose($handler);

when I open the file with any code editor I find data formatted correctly each number is in a new line but when I open the file with notepad I get this

090220179632;15678;1

while it should be like this

09022017
9632;1
5678;1

I tried "\n" instead of PHP_EOL but I got the same result.

So how to fix this issue so when I open the file in notepad it keeps the new line separator?

PHP User
  • 2,350
  • 6
  • 46
  • 87

0 Answers0