quartney Posted May 22, 2007 Share Posted May 22, 2007 Hi, I am trying to learn php from a book and am doing the sample exercises. I can't figure out why \n isn't making a new line for me. I am using php 5.2.0. Here is the code, and it is being output on one line. <?php $name = "Paul"; print "Your name is $name\n"; $name2 = $name; $age = 20; print "Your name is $name2, and your age is $age\n"; print "Goodbye, $name!\n"; ?> thanks a lot for your help! Q. Link to comment https://forums.phpfreaks.com/topic/52540-the-most-newbie-question-ever-regarding-n/ Share on other sites More sharing options...
simon551 Posted May 22, 2007 Share Posted May 22, 2007 try <br /> Link to comment https://forums.phpfreaks.com/topic/52540-the-most-newbie-question-ever-regarding-n/#findComment-259258 Share on other sites More sharing options...
quartney Posted May 22, 2007 Author Share Posted May 22, 2007 Hi Simon: I see that you suggested that I try br. The thing is, I don't care if the lines are separate or not, because this is a silly exercise. I just would like to know why \n isn't working for me. thanks, Q. Link to comment https://forums.phpfreaks.com/topic/52540-the-most-newbie-question-ever-regarding-n/#findComment-259259 Share on other sites More sharing options...
kenrbnsn Posted May 22, 2007 Share Posted May 22, 2007 If you're displaying the output in a browser window then the "\n" has no meaning to the browser and it changes it to a space. To display a newline in a browser window you need to use the "<br>" tag. If you do a "show source" you will see the newlines. Ken Link to comment https://forums.phpfreaks.com/topic/52540-the-most-newbie-question-ever-regarding-n/#findComment-259270 Share on other sites More sharing options...
quartney Posted May 22, 2007 Author Share Posted May 22, 2007 Thanks, that's exactly what I needed to know!!! Link to comment https://forums.phpfreaks.com/topic/52540-the-most-newbie-question-ever-regarding-n/#findComment-259273 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.