silverglade Posted July 21, 2008 Share Posted July 21, 2008 hi, im new to php and was wondering how i can insert new lines into all the output lines in this code, any help greatly appreciated. derek <?php $money = 30; $pet = "Kitten"; $new = sprintf("It costs $%3.2f for a %s.\n",$money,$pet); $new2 = sprintf("%'.-20s%3.2f",$pet,$money); echo $new; echo $new2; $today = date("Y/m/d"); echo $today; ?> Link to comment https://forums.phpfreaks.com/topic/115846-solved-making-a-new-line-in-php/ Share on other sites More sharing options...
LemonInflux Posted July 21, 2008 Share Posted July 21, 2008 hi, im new to php and was wondering how i can insert new lines into all the output lines in this code, any help greatly appreciated. derek <?php $money = 30; $pet = "Kitten"; $new = sprintf("It costs $%3.2f for a %s.\n",$money,$pet); $new2 = sprintf("%'.-20s%3.2f",$pet,$money) ."\n"; echo $new; echo $new2; $today = date("Y/m/d") ."\n"; echo $today; ?> Link to comment https://forums.phpfreaks.com/topic/115846-solved-making-a-new-line-in-php/#findComment-595543 Share on other sites More sharing options...
kenrbnsn Posted July 21, 2008 Share Posted July 21, 2008 A new line in the browser is produced by the <br> tag, not the "\n" character. Ken Link to comment https://forums.phpfreaks.com/topic/115846-solved-making-a-new-line-in-php/#findComment-595544 Share on other sites More sharing options...
Darklink Posted July 21, 2008 Share Posted July 21, 2008 \n produces a new line in the HTML code (\r\n for windows) <br/> will produce an actual line in the output. Link to comment https://forums.phpfreaks.com/topic/115846-solved-making-a-new-line-in-php/#findComment-595546 Share on other sites More sharing options...
silverglade Posted July 21, 2008 Author Share Posted July 21, 2008 thank you kenrbnsn and everyone. derek here is my corrected code. thanks. <?php $money = 30; $pet = "Kitten"; $new = sprintf("It costs $%3.2f for a %s.<br>",$money,$pet); $new2 = sprintf("%'.-20s%3.2f",$pet,$money) ."<br>"; echo $new; echo $new2; $today = date("Y/m/d") ."<br>"; echo $today; ?> Link to comment https://forums.phpfreaks.com/topic/115846-solved-making-a-new-line-in-php/#findComment-595553 Share on other sites More sharing options...
DarkWater Posted July 21, 2008 Share Posted July 21, 2008 Silverglade, you may want to use <br /> because it's XHTML compliant. Link to comment https://forums.phpfreaks.com/topic/115846-solved-making-a-new-line-in-php/#findComment-595555 Share on other sites More sharing options...
Darklink Posted July 21, 2008 Share Posted July 21, 2008 Woops. SMF didn't post my break tag. <br /> That's the one. Link to comment https://forums.phpfreaks.com/topic/115846-solved-making-a-new-line-in-php/#findComment-595560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.