Chapter 12 Review:

• How do you access a DOS console or terminal window on your computer? (See pages 379 through 382.)

In Windows, the DOS cmd prompt gets you there, while on Linx, the SSH terminal connection via a tool like Putty is one way to go.

• What are some good uses of the CLI? (See page 378.)

The Command Line Interface (CLI), can be used for quick checks of script

• How do you confirm the version of PHP you have? (See page 378.)

In the shell - use php with flag, -v will show php version information - or you could run phpinfo() in a php script/page.

• How do you execute a line or two of code using CLI? (See page 383.)

Use syntax php -r and then contain the lines to be run in quotes (single or double depending on type of CLI).

• How do you enter the CLI interactive shell? How do you exit it? (See page 386.)

To use a running prompt, use php -a. Interesting, the error message given when it's not working, indicates that it is working. Thus, if you see "interactive mode enabled", it is not working.

• If you want to execute a PHP script from the command line, what should the first line of code in that script be? What is that line called? (See page 388.)

The first line needs to be the "shebang" line - with the path to php - the following syntax: #!/usr/bin/php

• How do you run a PHP script using PHP CLI? (See page 391.)

To run a php script from the command line, you simply type: php <filename>.

• Through what variable do you access arguments passed when running a script through PHP CLI? What will the first item in that variable reference be? (See page 395.)

There are two $_SERVER array keys, 'argc' and 'argv', that contain the arguments, and the values respectively.

• How do you take input from the user? What are some of the ways you can validate the user’s input by type? (See pages 400 through 402.)

Taking input from the CLI involves use of the STDIN argument in a statement with a function like fscanf - which can use the sprintf type validators %s, %d etc to validate.

• How do you use PHP CLI to test a script in your Web browser? How do you change the Web root directory used by the PHP CLI server? (See page 405.)

If supported, the php -S localhost:port# can create a vehicle for testing locally. To change the root directory use the follwing: php -S localhost: 8000 -t /path/ to/ directory.