jj33 Posted July 10, 2008 Share Posted July 10, 2008 Im a bit new but how do you make so that you have a string that looks like <pre> $string = "paragraph second line ";</pre> and still keep the newline. in html i could have <pre>paragraph\<br\>second line</pre> Link to comment https://forums.phpfreaks.com/topic/114030-solved-new-line/ Share on other sites More sharing options...
unidox Posted July 10, 2008 Share Posted July 10, 2008 \n Link to comment https://forums.phpfreaks.com/topic/114030-solved-new-line/#findComment-586057 Share on other sites More sharing options...
Guest Xanza Posted July 10, 2008 Share Posted July 10, 2008 Use "\n" like unidox said... Example Useage: while($row = mysql_fetch_array($result)) { $out = $row["id"].','; $out .= $row["id_question"].','; $out .= $row["answer"].','; $out .= $row["position"].'\n'; $out .= $row["status"].'\n'; } echo $out; Link to comment https://forums.phpfreaks.com/topic/114030-solved-new-line/#findComment-586062 Share on other sites More sharing options...
jj33 Posted July 10, 2008 Author Share Posted July 10, 2008 so i would have <pre> $string = "paragraph \n second line"; </pre> to have paragraph second line Link to comment https://forums.phpfreaks.com/topic/114030-solved-new-line/#findComment-586066 Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 Just a correction. while($row = mysql_fetch_array($result)) { $out = $row["id"].','; $out .= $row["id_question"].','; $out .= $row["answer"].','; $out .= $row["position"]."\n"; $out .= $row["status"]."\n"; } echo $out; The newline \n char will not be interpolated within single quotes. so i would have $string = "paragraph \n second line"; to have paragraph second line Yes, unless of course your wanting to output html newlines, in which case you still use the <br /> tag. Link to comment https://forums.phpfreaks.com/topic/114030-solved-new-line/#findComment-586067 Share on other sites More sharing options...
Guest Xanza Posted July 10, 2008 Share Posted July 10, 2008 The newline \n char will not be interpolated within single quotes. Ok, thanks! I did not know that. I really don't use \n to tell you the truth, I usually just use the standard HTML "<br>"... Any advantage to using \n compared to HTML - besides the quick syntax? Link to comment https://forums.phpfreaks.com/topic/114030-solved-new-line/#findComment-586072 Share on other sites More sharing options...
jj33 Posted July 10, 2008 Author Share Posted July 10, 2008 you mean <pre>$string = ' paragraph \n second line ' </pre> outputs <pre> paragraph \n second line</pre> Link to comment https://forums.phpfreaks.com/topic/114030-solved-new-line/#findComment-586075 Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 Any advantage to using \n compared to HTML - besides the quick syntax? A newline \n char only effects your html source code. It isn't at all relvent to html and what is output by a browser. I'm in the habbit of using the \n newline simply because I do alot of shell scripting. Link to comment https://forums.phpfreaks.com/topic/114030-solved-new-line/#findComment-586078 Share on other sites More sharing options...
Guest Xanza Posted July 10, 2008 Share Posted July 10, 2008 jj33, what he means is $string = "This is line number one \n and this is line number two"; will output: This is line number one and this is line number two Additionally, the same effect can be obtained by using <br> $string = "This is line number one<br>and this is line number two"; which will output: This is line number one and this is line number two A newline \n char only effects your html source code. It isn't at all relvent to html and what is output by a browser. I'm in the habbit of using the \n newline simply because I do alot of shell scripting. Ok! Sexy, thanks for the information! Link to comment https://forums.phpfreaks.com/topic/114030-solved-new-line/#findComment-586079 Share on other sites More sharing options...
jj33 Posted July 10, 2008 Author Share Posted July 10, 2008 Thanks Link to comment https://forums.phpfreaks.com/topic/114030-solved-new-line/#findComment-586080 Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 Additionally, the same effect can be obtained by using If you read my last post you will note \n and <br /> do not have the same effect at all. \n will not effect html, if you want a newline to appear in a browser you need to use htmls <br /> tag. \n will only effect the html source. ie; what you see when you rightclick->viewsource. Link to comment https://forums.phpfreaks.com/topic/114030-solved-new-line/#findComment-586081 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.