Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

Chapter 3. The PHP Interpreter

This chapter discusses how PHP runs, both through the command line and through a web server, how PHP can be extended through built-in and third-party modules, and what can cause your scripts to terminate unexpectedly.

Running PHP Scripts

You can execute your scripts in one of two ways: through a web server where the output is sent to a web browser, or through the command-line interface (CLI) where the output is sent to standard output. Of the two, the former is more popular, but the latter is steadily growing in popularity.

The primary difference between outputting text to the command line and to a web browser is the format of new lines—through the CLI, you need to use \n for a new line, whereas for web browsers, you need to use the HTML line break, <br />. If you want to take a script designed for CLI and make it work through the Web, swap \n for <br />, and vice versa for converting web scripts to command line scripts.

If everything is configured properly, running scripts through your web server is as simple as putting the PHP script into your web server's public directory, then navigating to the appropriate URL with your browser. Running scripts through the command line is done using the CLI interpreter, which, if you are using Windows, is php.exe in the directory of your PHP installation. That is, if you have installed PHP into c:\php, the CLI program will be c:\php\php.exe. If you are using Unix, the availability of CLI PHP is down to how you installed ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page