Title: Strings,Dates, and Times ($$$)
Course: PHP/MySQL Course

printr

Read all about printf and sprintf on pages 171 to 180. Also take a look at the manual page here: springf

Notes:
- specifying the width of a column will not work in a browser unless you output the code a s fix width font and inside of a <pre> tag to retain the spaces.
- You can simplify the argument swapping format string by using single quotes, so you don't have to escape the $:
'%2$02d/%1$02d/%3$d<br />'
- Another useful function the book does not show is the number_format function, it will add commas every thousand. Here is some sample code to see what it does:

$price = 45240.75;
$milesAroundEarth = 24901.55;
echo '<br />$' . number_format($price); // no decimal places
echo '<br />$' . number_format($price,2); // two decimals
echo '<br />' . number_format($milesAroundEarth, 1); // one decimal?>

this outputs:

$45,241
$45,240.75
24,901.6

Question:

what does the following code output?

$x = 54.23;
printf('%07d', $x);

- 0000054
- 054
- 54
- 54.2

working strings

Read more about working with strings from page 180 to 191.

Question?

What will this code output:

$fname = "test.doc";
echo substr($fname, -4);

- .doc

time and dates

Read pages 191 to 197 about time and dates.

Note:
- I have to point you to a real useful function not covered the strtotime function. Read strtotime

This is a really cool function tha converts a lot of what a user might type for a date or time, such as 1 week ago, or yesterday.

Question:

what unit of measure is the time stamp in?

- seconds
- hours
- minutes and seconds
- miliseconds