leovn Posted April 8, 2006 Share Posted April 8, 2006 My code was :<?php echo "Testing :\n"; echo "A new line";?>Then it's ouput : Testing :A new line ... What should i do to make a new line ? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 8, 2006 Share Posted April 8, 2006 try:<?php echo "Testing :\r\n"; echo "A new line";?> Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted April 8, 2006 Share Posted April 8, 2006 Look at the source code in your browser...the newline is there, it just doesn't print them in the html display...either do:[code]echo "<pre>line one\nlinetwo";[/code]or[code]echo "line one <br> line two";[/code]New lines are not html and therefor unless the pre is around it, the browser will ignore them in the display. Quote Link to comment Share on other sites More sharing options...
neylitalo Posted April 8, 2006 Share Posted April 8, 2006 ToonMariner's got something, too... different operating systems have different new line characters:[code]Windows: \n\rLinux: \nMac: \r[/code]\n is new line, while \r is carriage return - Windows apps usually require both. And you can also check out the nl2br function - you give it a string that contains new line characters, and it will return a string with HTML line breaks in their place. :)the <pre> tag is a personal favorite of mine - especially for print_r and var_dump. Without <pre>, the output from two functions gets messy fast. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 8, 2006 Share Posted April 8, 2006 If you are using this code:[code]<?phpecho "Testing :\n";echo "A new line";?>[/code]and viewing the page in a web browser then it wont show like so:Testing :A new lineHowever it will if you go to View -> Source Code in your web browser. Web browsers ignore whitespace characters such as \n, \r \t etc. This is why your text appears in one line. To resolve this you will have to tell your browser to put in a new line after Testing: . Using the line break tag manualy. Or you could do this:[code]<?php$str = "Testing: \nA new line";echo nl2br($str);?>[/code]With nl2br it doesn't mater whether you use \r or \n as it will convert both into <br /> automatically. However if you are writting the output to a file you will need to use \r\n for Windows, \r for Mac and \n for Linux as others have pointed out above. Quote Link to comment Share on other sites More sharing options...
leovn Posted April 9, 2006 Author Share Posted April 9, 2006 Thank you very much !!! It's work now , thanks all again ^^ 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.