Chapter 7 Answers

Question 7-1

The conversion specifier you would use to display a floating-point number is %f.

Question 7-2

To take the input string “Happy Birthday” and output the string “**Happy”, you could use a printf statement such as printf("%'*7.5s", "Happy Birthday");.

Question 7-3

To send the output from printf to a variable instead of to a browser, you would use sprintf instead.

Question 7-4

To create a Unix timestamp for 7:11am on May 2nd 2016, you could use the command $timestamp = mktime(7, 11, 0, 5, 2, 2016);.

Question 7-5

You would use the “w+” file access mode with fopen to open a file in write and read mode, with the file truncated and the file pointer at the start.

Question 7-6

The PHP command for deleting the file file.txt is unlink('file.txt');.

Question 7-7

The PHP function file_get_contents is used to read in an entire file in one go. It will also read them from across the Internet if provided with a URL.

Question 7-8

The PHP associative array $_FILES contains the details about uploaded files.

Question 7-9

The PHP exec function enables the running of system commands.

Question 7-10

In XHTML 1.0, the tag <input type=file name=file size=10> should be replaced with the following correct syntax <input type="file" name="file" size="10" />, because all parameters must be quoted, and tags without closing tags must be self closed using />.

Get Learning PHP, MySQL, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.