Can't figure out how to "add" to a text file

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
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Can't figure out how to "add" to a text file

Post by djwk »

Ok

Here's my code:
$1 = $1 + "\n".$2;

And here's the output
07

I want the output to be:
0
7

I just can't figure out what I'm doing wrong, anyone?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

This output is displayed in a html browser?
Then you need <br /> instead of \n
You might be interested in http://de3.php.net/nl2br
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Post by djwk »

Ahh sorry, I hadn't actually saved it to a text file.. sorry for wasting your time
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Or stick <pre> tags around the output if you must use \n
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Post by djwk »

I've done it to a file now and it's not doing a new line

It has the value of $1 then the little square symbol thing then the value of $2...


Any help?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

\r\n or try the PHP_EOL constant (if you are running PHP 4.3.10+ or PHP 5.0.2+)
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Post by djwk »

I've fixed it now, nevermind, thanks for all your help :)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

or set the header to text/plain...

:rofl: we can't stop!!!!!
Post Reply