Workshop


The workshop is designed to help you anticipate possible questions, review what you've learned, and begin putting your knowledge into practice.

Quiz

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?

Answers

1.

The conversion specifier f is used to format an integer as a double:

 printf("%f", 33); 

2.

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); 

3.

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); 

4.

The substr() function extracts and returns a substring.

5.

The ltrim() function removes white space from the start of a string.

6.

The explode() function will split up a string into an array.

7.

Use time().

8.

The getdate() function returns an associative array whose elements contain aspects of the given date.

9.

Use date().

10.

You can check a date with the checkdate() function.

Activities

  1. Create a feedback form that accepts a user's full name and an email address. Use case conversion functions to capitalize the first letter of each name the user submits and print the result back to the browser. Check that the user's email address contains the @ symbol and print a warning otherwise.

  2. Create an array of doubles and integers. Loop through the array, converting each element to a floating-point number with a precision of 2. Right-align the output within a field of 20 characters.

  3. Create a birthday countdown script. Given form input of month, day, and year, output a message that tells the user how many days, hours, minutes, and seconds until the big day.



Sams Teach Yourself PHP MySQL and Apache All in One
Sams Teach Yourself PHP, MySQL and Apache All in One (4th Edition)
ISBN: 067232976X
EAN: 2147483647
Year: 2003
Pages: 333
Authors: Julie Meloni

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net