I don't understand very well the "new line character" of php? Can someone please

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

Guest
help me? This is my first time I'm working with PHP. What I need is to save a text file on my server using PHP. For example:

I have tree variables and I need to save each variable in on a different line. How can I do this?

I have read allot about this on the internet and they say that different OS have a different"new line character". But what OS are they talking about. The one of the server or the one of the clients computer.

My servers OS is linux.
I know that \n is a new line char. But It is for Linux. Windows uses \r\n and mac uses \r.
 
They probably meant something else; I won't bore you with the details. What you're looking to do would be like this:

fwrite( $FileHandler, $Variable1 . "\n" . $Variable2 . "\n" . $Variable3 );

The period ' . ' will append a break in our function. So in this case we used the period to append the new line string. Which anything between the quotes is considered a string. In this case we only put the newline character in our string. The newline character is like saying you want to go to the next line with w/e follows the newline character.

So if we do:

echo ( "Hello \nworld" );
When you run the script it will look like:

Hello
world





Words of Wisdom,
- Hex
 
Back
Top