Page 1 of 1

Very new to php. Need line break help.

Posted: Sun Nov 22, 2009 6:18 pm
by citrustech
Hello all!
So, i have been messing around with php for a year or now but not in a serious manner just editing things in cms's. Well i would like to start learning so i can starting doing some real stuff. So here's where i'm stuck:
I made small script where when a user logs onto the site, it shows their ip address. It then logs their ip address into a .txt file. But there are no line breaks between the ip addresses. I searched around and found many solutions, but there examples were confusing.

Code: Select all

fputs($fp, $rip);       // Need the line break to be before the $rip.
Thanks a lot ya guys!

Re: Very new to php. Need line break help.

Posted: Sun Nov 22, 2009 7:59 pm
by requinix
Line breaks are different according to operating system. Windows uses \r\n, Unix and friends use \n, and Macs use \r. You should be using the right line break for whatever PHP is running on. Luckily, since determining the OS can be hard, PHP has a constant named PHP_EOL.

To concatenate (combine) two strings you use the . operator: $variableA . $variableB.

Code: Select all

fputs($fp, $rip . PHP_EOL);
Yes, the line break is after the $rip, but that's actually better.