Very new to php. Need line break help.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
citrustech
Forum Newbie
Posts: 4
Joined: Sun Nov 22, 2009 6:14 pm

Very new to php. Need line break help.

Post 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!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
Post Reply