Workshop

The workshop is designed to help you anticipate possible questions, review what you've learned, and begin learning how to put 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.

A1:

You use the conversion specifier f to format an integer as a double:

printf("%f", 33);

2:

How would you pad the conversion you effected in question 1 with zeros so that the part before the decimal point is four characters long?

A2:

You can pad the output from printf() with the padding specifier that is, a space or a zero followed by a number representing the number of characters you want to pad by.

printf("%04f", 33);

3:

How would you specify a precision of two decimal places for the floating-point number you have been formatting in the previous questions?

A3:

The precision specifier consists of a 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:

What function would you use to extract a substring from a string?

A4:

The substr() function extracts and returns a substring.

5:

How might you remove whitespace from the beginning of a string?

A5:

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

6:

How would you break up a delimited string into an array of substrings?

A6:

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

7:

Write an SQL query to find the starting position of a substring "grape" in a string "applepearbananagrape".

A7:

SELECT LOCATE('grape', 'applepearbananagrape');

8:

Write a query that selects the last 5 characters from the string "applepearbananagrape".

A8:

SELECT RIGHT("applepearbananagrape", 5);

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. Using both PHP and MySQL, practice using functions within functions, such as making case changes on substrings and concatenating strings.



Sams Teach Yourself PHP, MySQL and Apache in 24 Hours
Sams Teach Yourself PHP, MySQL and Apache in 24 Hours
ISBN: 067232489X
EAN: 2147483647
Year: 2005
Pages: 263

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