A Walk Through PHP
PHP pages are generally HTML pages with PHP commands embedded in them. This is in contrast to many other dynamic web page solutions, which are scripts that generate HTML. The web server processes the PHP commands and sends their output (and any HTML from the file) to the browser. Example 1-1 shows a complete PHP page.
Example 1-1. hello_world.php
<html><head><title>Look Out World</title></head><body><?php echo "Hello, world!"; ?></body></html>
Save the contents of Example 1-1 to a file, hello_world.php, and point your browser to it. The results appear in Figure 1-2.

Figure 1-2. Output of hello_world.php
The PHP echo command
produces output (the string “Hello, world!” in this case) inserted into
the HTML file. In this example, the PHP code is placed between the
<?php and ?> tags. There are other ways to tag your PHP
code—see Chapter 2 for a full description.
Configuration Page
The PHP function phpinfo()
creates an HTML page full of information on how PHP was installed and is
currently configured. You can use it to see whether you have particular
extensions installed, or whether the php.ini file has been customized. Example 1-2 is a complete page
that displays the phpinfo()
page.
Example 1-2. Using phpinfo()
<?phpphpinfo();?>
Figure 1-3 shows the first part of the output of Example 1-2.
Figure 1-3. Partial output of phpinfo()
Forms
Example 1-3 creates and processes a form. ...
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.
Read now
Unlock full access