nisroc Posted December 1, 2008 Share Posted December 1, 2008 Just started learning php and i think all is going well, but with what i have read so far i have become confused with a couple things and hope maybe some one can explain them better than the book does. 1st. \n I have seen this used in a php before and i do understand that it to start a new line. However when ever I use it in a string i do not get a new line. Problem is i only know one type of output for php and that is a web page. how would i beable to see the effect of \n in php output? 2nd. With this code <?php $money = 30; $pet = "Kitten"; $new = sprintf("It costs $%03.2f for a %s.\n",$money,$pet); $new2 = sprintf("%’.-20s%3.2f",$pet,$money); echo $new; echo $new2; ?> My output is: It costs $30.00 for a Kitten. .-20s30.00 Everything in $new works fine but $new2 should be, "Kitten.............. 30.00". Im not sure why it is doing this. To help anyone figure out why i am using PhpEd to learn on, but after uploading it to my web hosting i got the same output. Any idea why? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/134951-newbie-questions/ Share on other sites More sharing options...
MatthewJ Posted December 1, 2008 Share Posted December 1, 2008 \n makes a new line in a text file... or in the source of the html page echo "<p>par 1</p><p>par 2</p><p>par 3</p>"; all three sets of <p> tags would be on the same line in the page source echo "<p>par 1</p>\n<p>par 2</p>\n<p>par 3</p>"; would put them on three separate lines in the source code Link to comment https://forums.phpfreaks.com/topic/134951-newbie-questions/#findComment-702807 Share on other sites More sharing options...
MatthewJ Posted December 1, 2008 Share Posted December 1, 2008 This line $new2 = sprintf("%’.-20s%3.2f",$pet,$money); Should be $new2 = sprintf("%'.-20s%3.2f",$pet,$money); Link to comment https://forums.phpfreaks.com/topic/134951-newbie-questions/#findComment-702810 Share on other sites More sharing options...
nisroc Posted December 1, 2008 Author Share Posted December 1, 2008 ah thanks you very much for this explanation Matthew, makes a lot more sense with the \n now and with the code was just wrong char. again thanks Link to comment https://forums.phpfreaks.com/topic/134951-newbie-questions/#findComment-702819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.