Mantis_61 Posted July 23, 2006 Share Posted July 23, 2006 Hello readers, I don't know if anyone can solve this without sitting behind my machine but I'm tripping over my shoe laces here. This is all so simple but still won't work! my \n to break a line never works. I've tried with print() and echo?I'm using php5.1.1 on Windows and can't figure it out. Is this bad syntax?...echo "let's break \n it down!"I've also tried...echo "lets try this then \r\n STILL NOTHING!"The escape isn't displayed but my line doesn't break either?I've had other weird things cause errors in the past.I've also tried uninstalling and reinstalling the engine as well as the server.Is this an OS or server issue?Sorry for posting something so minor but it has become a problem. Quote Link to comment Share on other sites More sharing options...
trq Posted July 24, 2006 Share Posted July 24, 2006 How are you viewing this? Through a browser? \n does not effect the html output, view the source (right click) to view the output of....[code=php:0]echo "lets try this then\n STILL NOTHING!"[/code] Quote Link to comment Share on other sites More sharing options...
scs Posted July 24, 2006 Share Posted July 24, 2006 Well I don't know your background knowledge of php/html. so excuse me if i'm obvious. when you do this:echo "let's break \n it down!"you will see this in the browser.let's break it down!But your code will be:let's break it down!If you get where I'm going. I think thats your problem. If you are trying to breakline with \n you wont see it in the browser. So you need br tag. I hope thats what you were trying to do. If not explain a little more of what you want your end result to be. Quote Link to comment Share on other sites More sharing options...
Mantis_61 Posted July 24, 2006 Author Share Posted July 24, 2006 I guess that explains that. I was trying to use it for an easier type up vs. using html. As far as my computer background that goes back about 2 years of on and off recreational reading. Still venturing out to the older stuff and the UNIX basis for reference. Thanks for the answer. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 24, 2006 Share Posted July 24, 2006 This is becuase web browsers ignores whitespace characters, \n \r etc, howver in actuall fact they are still there, but in your source, right click view source.The way around this to use nl2br which will conver line breaks/carriage returns in html line break (< br />), which the browser will not ignore. Heres a few examples:[code]<?php// our demo string:$str = "This line\n has line breaks and \rcarriage \n\n\nreturns!";// this wont display the line breaks/carriage returnsecho $str;echo "<br /><br />";// however this will:echo nl2br($str);?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.