Deitel & Associates, Inc. Logo

Back to
digg.png delicious.png blinkit.png furl.png
Internet & World Wide Web How to Program, 3/e
Internet & World Wide Web How to Program, 3/e

© 2004
pages: 1420

Amazon logo

This tutorial presents four PHP programs that introduce PHP programming concepts, including comments, variables, operators, keywords, type conversions, scripting delimiters, interpolation, string concatenation, control statements and arrays. The techniques you learn hear are used in our subsequent tutorials:
[Note: This tutorial is an excerpt (Section 26.2) of Chapter 26, PHP, from our textbook Internet & World Wide Web How to Program, 3/e. This tutorial may refer to other chapters or sections of the book that are not included here. Permission Information: Deitel, Harvey M. and Paul J., INTERNET & WORLD WIDE WEB HOW TO PROGRAM, 3/E, 2004, pp.900-909. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]
26.2 Introduction to PHP Programming
The power of the Web resides not only in serving content to users, but also in responding to requests from users and generating Web pages with dynamic content. Interactivity between the user and the server has become a crucial part of Web functionality. While other languages can perform this function as well, PHP was written specifically for interacting with the Web.
PHP code is embedded directly into XHTML documents. This allows the document author to write XHTML in a clear, concise manner, without having to use multiple print statements, as is necessary with other CGI-based languages.
PHP script file names usually end with .php, although a server can be configured to handle other file extensions. To run a PHP script, PHP must first be installed on your system. PHP 4.3.3 is available on the CD-ROM accompanying this book. Please refer to the PHP installation and configuration instructions available on the CD-ROM. The most recent version of PHP always can be downloaded from

and the latest installation instructions are available at

Although PHP can be used from the command line, a Web server is necessary to take full advantage of the scripting language. Before continuing, please copy the .php, .html and .txt files and the images directory from the Chapter 26 examples directory on the CD-ROM to the Web server's root directory (e.g., C:\Inetpub\wwwroot for IIS or C:\Program Files\Apache Group\Apache2\htdocs for Apache).
Simple PHP Program
Figure 26.1 presents a simple PHP program that displays a welcome message.
Fig. 26.1 Simple PHP program.
1   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2   "">
4   <!-- Fig. 26.1: first.php -->
5   <!-- Our first PHP script -->
7   <?php
8      $name = "LunaTic"; // declaration
9   ?>
11   <html xmlns = "">
12      <head>
13          <title>A simple PHP document</title>
14       </head>
16       <body style = "font-size: 2em">
17          <p>
18            <strong>
20                <!-- print variable name's value -->
21               Welcome to PHP, <?php print( "$name" ); ?>!
22             </strong>
23          </p>
24       </body>
25   </html>


Page 1 | 2 | 3 | 4 | 5 | 6 | 7
Other PHP Tutorials
PHP Tutorial 1: Introduction to PHP
PHP Tutorial 2: Creating Simple PHP Programs (You are here)
PHP Tutorial 3: String Processing and Regular Expressions
PHP Tutorial 4: Form Processing and Business Logic