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; ?> Quote Link to comment 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; ?> Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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; ?> Quote Link to comment 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. Quote Link to comment 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. 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.