473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Line feed not working in windows (notepad)

chathura86
227 100+
hi,

i have the following code which writes content to a file

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy \n fffffffffffffffffffffffffffffffff \n";
  4.  
  5. file_put_contents ("test.txt", $x);
  6. ?>
  7.  
in fedora when i open the file in vi/vim/gedit (fedora) and wordpad (winxp)

it shows the line breaks

but not in the notepad (winxp)

but if i updated the code to insert the carriage return (\r) it will
display the line breaks in the notepad also

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n\r yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy \n\r fffffffffffffffffffffffffffffffff \n\r ";
  3.  
  4. file_put_contents ("test.txt", $x);
  5. ?>
  6.  
i wonder why note pad required the \r also

thanks in advance

Chathura Bamunusinghe
Apr 4 '10 #1

✓ answered by Markus

I don't know the specifics of *why* it's like that, but I do know this problem has been abstracted away into the PHP constant PHP_EOL. Using this constant, your application can be new-line agnostic.

If you're on windows, this constant is defined as "\n\r"; on (an older) Mac, "\r"; otherwise, "\n".

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. echo "My PHP application is", PHP_EOL;
  4. echo "new-line agnostic.", PHP_EOL;
  5.  

3 6603
Markus
6,050 Expert 4TB
I don't know the specifics of *why* it's like that, but I do know this problem has been abstracted away into the PHP constant PHP_EOL. Using this constant, your application can be new-line agnostic.

If you're on windows, this constant is defined as "\n\r"; on (an older) Mac, "\r"; otherwise, "\n".

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. echo "My PHP application is", PHP_EOL;
  4. echo "new-line agnostic.", PHP_EOL;
  5.  
Apr 4 '10 #2
Atli
5,058 Expert 4TB
@Markus
I can sort of understand both the Windows and Unix versions, but not really the old Mac version.

The Windows version emulates the way a typewriter works. First snapping back to the start of the line "\r", and then pulling the paper one line up "\n".

The Unix version is more "digital". Text is a string of characters, and when you add a new line, it is natural for the next character after the "\n" to become the first character of the new line. (Think; splitting the text into lines on "\n", and printing each line.) -- For the new line to start at the same point where it's parent ended, the new line would have to be padded with spaces, which is just pointless. The "\r" has no purpose in this context.

The old Mac version makes no sense. The "\r", carriage-return, only ever returned a typewriter to the start of the same line. How that results in you being in the next line I do not know. -- Which is probably partly why they abandoned it. The latest versions apparently use the Unix EOF now, or so I hear. (Well, the latest Macs are Unix based, so that makes sense.)


It kind of surprises me that Notepad still doesn't recognize "\n" as a new-line, or at least has an option to make it recognize it. It's such a small modification that would make such a large difference.- I don't know how many times I've tried to make minor modifications to my PHP code in Notepad, only to have it all be wrapped into a single line.
Apr 5 '10 #3
Markus
6,050 Expert 4TB
Updated :)
Apr 5 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Neil S. | last post by:
I am writing an ISAPI filter which is using CAPICOM to encrypt and decrypt cookie information. I've found that the encryption string being returned by CAPICOM a has carriage control and line feed....
4
by: Robert | last post by:
Is there some way to suppress the automatic line feed in the detail section of a report in Access? I would like the detail to print out to the right of the existing one. The next line would be...
4
by: Jrferguson | last post by:
I am 'dabling' with a piece of code: int k; for(k = 1; k < 6; k++) { printf("%3d\f", k) } with the expectation that the output would be something like: 1 2
3
by: David N. | last post by:
Hi All, I spent too much time on trying to get the CrLf into a string, which contains embedded SQL statements that can be executed by the SQLClient.SqlCommand. Note that these SQL statements...
1
by: Raed Sawalha | last post by:
Is it possible to make the following div to generate automatic line feed when user start writing and reaches the DIV bounderies like in textarea, the case I have when type a continous chars without...
1
by: suresh_nsnguys | last post by:
Hello sir, I am facing some problem while sending SMS and MMS email message to moble device using PHP and HTML. MMS email message is displaying fine with proper linefeed.but SMS message...
1
by: Nalaka | last post by:
Hi, We are sending SMS messages using our ASDP.net site (C# code).... How do I add a "Line Feed" character to the string that we are sending? Any help is deeply appreciated Thanks Nalaka
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
1
by: rengaraj | last post by:
Dear Experts, I am new to XML I want to create an Interview Questions Bank (Intra Net) for our institution. I preferred to store the Question & Answer in xml sheet. But if i vew the xml in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.