idire Posted November 18, 2008 Share Posted November 18, 2008 I'm trying to make php output nicely formatted html code so tried: <?php echo $data.'\n'; ?> which doesnt work. also tried: <?php echo $data.'\r\n'; ?> also this does nothing: <?php echo 'Username: \n '.$row->username."\r\n"; ?> Link to comment https://forums.phpfreaks.com/topic/133238-solved-why-doesnt-n-work/ Share on other sites More sharing options...
revraz Posted November 18, 2008 Share Posted November 18, 2008 Did you try <BR /> ? Link to comment https://forums.phpfreaks.com/topic/133238-solved-why-doesnt-n-work/#findComment-692940 Share on other sites More sharing options...
idire Posted November 18, 2008 Author Share Posted November 18, 2008 <br/> works but thats not what i'm trying to do. I'm trying to make the outputted html appear on a new line, instead of going on forever so <table><tr><td></td></tr></table> goes to: <table> <tr> <td> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/133238-solved-why-doesnt-n-work/#findComment-692941 Share on other sites More sharing options...
gmcalp Posted November 18, 2008 Share Posted November 18, 2008 echo "<h3>".$data."</h3>\n"; Link to comment https://forums.phpfreaks.com/topic/133238-solved-why-doesnt-n-work/#findComment-692945 Share on other sites More sharing options...
idire Posted November 18, 2008 Author Share Posted November 18, 2008 echo "<h3>test</h3> test"; gives the same output as: echo "<h3>test</h3> \n test"; h3 has a new paragraph started after it anyway, so that tells me nothing? Link to comment https://forums.phpfreaks.com/topic/133238-solved-why-doesnt-n-work/#findComment-692946 Share on other sites More sharing options...
Mark Baker Posted November 18, 2008 Share Posted November 18, 2008 OK then, try: echo "<table>\n<tr>\n<td>\n</td>\n</tr>\n</table>\n"; But I think you'll find the original example worked perfectly Link to comment https://forums.phpfreaks.com/topic/133238-solved-why-doesnt-n-work/#findComment-692959 Share on other sites More sharing options...
DarkerAngel Posted November 18, 2008 Share Posted November 18, 2008 [removed post] Link to comment https://forums.phpfreaks.com/topic/133238-solved-why-doesnt-n-work/#findComment-692960 Share on other sites More sharing options...
trq Posted November 18, 2008 Share Posted November 18, 2008 \n works as expected when between double quotes. Link to comment https://forums.phpfreaks.com/topic/133238-solved-why-doesnt-n-work/#findComment-692961 Share on other sites More sharing options...
idire Posted November 18, 2008 Author Share Posted November 18, 2008 Adding ."\n"; onto the end of the echoes seems to work. Never knew there was a difference between single and double quotes. Stupid me. Thanks all. Link to comment https://forums.phpfreaks.com/topic/133238-solved-why-doesnt-n-work/#findComment-692966 Share on other sites More sharing options...
gmcalp Posted November 18, 2008 Share Posted November 18, 2008 from your first example, this should work: <?php echo "Username: ".$whateverdatayouwant."\n"; ?> Link to comment https://forums.phpfreaks.com/topic/133238-solved-why-doesnt-n-work/#findComment-692968 Share on other sites More sharing options...
trq Posted November 18, 2008 Share Posted November 18, 2008 Never knew there was a difference between single and double quotes. Variables and escape sequences are interpolated within double quotes only. Link to comment https://forums.phpfreaks.com/topic/133238-solved-why-doesnt-n-work/#findComment-692970 Share on other sites More sharing options...
idire Posted November 18, 2008 Author Share Posted November 18, 2008 Ah so use double quotes when you want the server to look inside the quotes for variables and \n \t etc. Thanks Link to comment https://forums.phpfreaks.com/topic/133238-solved-why-doesnt-n-work/#findComment-692981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.