fwrite($handle,PHP_EOL); not working in Linux server

fwrite($handle,PHP_EOL); not working in Linux server , is there Any alternatives in our yii ? I want to write to a .txt file, in windows fwrite($handle,PHP_EOL); is working… Linux its only taken as a single ‘space’.

The value of PHP_EOL is different on Linux then on Windows…

Check this link - http://stackoverflow.com/questions/4975411/when-do-i-use-php-eol-instead-of-n-and-vice-versa-ajax-jquery-client-problem

fwrite($handle,"\n") is also not working, its also a space.

is there anything to do with httpd.conf file ?

i want to write a new line in .txt file. PHP_EOL is working in windows but its only writing a space in Linux server

It’s not a space… it’s ‘\n’… on Linux that is the code for a new line… (have you read the link I posted before?)

On windows the code for a new line is "\r\n"… so if you want that to be written even on linux server… just use


fwrite($handle,"\r\n");

gottt itt… I used fwrite($handle,"\r\n") instead of fwrite($handle,PHP_EOL) … its working in Both Linux and Windows…

Thanks mdomba …

first I thought the reverse may work. then realizd "\r\n" is the solution . At that time mdomba replied the same.

The reality is that it was working fine in both environments. It’s just that the application you opened it in is only displaying breaks for \r. Of course this is only an issue with lazy Windows based applications, there are plenty out there that render Unix line endings fine.

Yeah thats right…

@Say_Ten,

How to know application I opened whether displaying breaks for \r only?

At first I have no problem to display output using PHP_EOL as shown below.




str_replace(PHP_EOL, '<br />', $string);



BUT after I enhance my codes, it is not work then(only display as a space), so I just use ‘\n’ instead PHP_EOL. It works well with ‘\n’.




str_replace('\n', '<br />', $string);



I tried to insert PHP_EOL into database, when I retrieve, it shows ‘\n’.

But why when I want to display as HTML, I tried to replace PHP_EOL with <br />, but it just display as a space?

Sorry I just want to know why is this happen :) even I works well with replace ‘\n’ instead.

Thank you.