Jump to content

Newbie questions


nisroc

Recommended Posts

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

\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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.