1: | What conversion specifier would you use with printf() to format an integer as a double? Indicate the full syntax required to convert the integer 33. |
2: | How would you pad the conversion you effected in question 1 with zeroes so that the part before the decimal point is four characters long? |
3: | How would you specify a precision of two decimal places for the floating-point number we have been formatting in the previous questions? |
4: | What function would you use to extract a substring from a string? |
5: | How might you remove white space from the beginning of a string? |
6: | How would you break up a delimited string into an array of substrings? |
7: | Using PHP, how do you acquire a Unix timestamp that represents the current date and time? |
8: | Which PHP function accepts a timestamp and returns an associative array that represents the given date? |
9: | Which PHP function do you use to format date information? |
10: | Which PHP function could you use to check the validity of a date? |
| |
A1:
| The conversion specifier f is used to format an integer as a double:
printf("%f", 33 );
|
| |
A2:
| You can pad the output from printf() with the padding specifierthat is, a space or a zero followed by a number representing the number of characters you want to pad by.
printf("%04f", 33 );
|
| |
A3:
| The precision specifier consists of dot (.) followed by a number representing the precision you want to apply. It should be placed before the conversion specifier:
printf("%04.2f", 33 );
|
| |
A4:
| The substr() function extracts and returns a substring. |
| |
A5:
| The ltrim() function removes white space from the start of a string. |
| |
A6:
| The explode() function will split up a string into an array. |
| |
A7:
| Use time(). |
| |
A8:
| The getdate() function returns an associative array whose elements contain aspects of the given date. |
| |
A9:
| Use date(). |
| |
A10:
| You can check a date with the checkdate() function. |