home news blogs forums events research newsletter whitepapers careers


UBM Network Computing
TechWeb
HOT PICKS

IMMERSE YOURSELF:

SOA

  |

Data Center

  |

802.11n

  |

Data Privacy

  |
APO  |

Virtualization

  |

NAC

  |

Security

  |

Network Mgmt

  |

Enterprise Apps

  |

Storage & Servers





Chapter 2: Beginning PHP 4

December 18, 2000

Brought to you by:




Table of contents:
Writing PHP Programs

In the first chapter, we introduced PHP and went through the decidedly non-trivial process of installing it on your web server, and getting PHP itself up and running. What we didn't do in any detail is look at an example of PHP code in action, other than to test that our installation was functioning correctly. The first thing that we will look at in this chapter is how to write a very basic PHP page and get it functioning on our web server, while answering questions about how it works and what the code is doing. Once we've worked through this, we'll examine the role of the web server and find out, in greater detail, how PHP actually works.

Once we've established, at a fairly basic level, what goes on under the hood of PHP, we will take a look at some of the principal building blocks of the language, and how we can use PHP to store information in our web pages. Every programming language requires a mechanism for storing information and attaching it to an identifier, which you can then reference for later use. For example, how do you store dates, such as a set of people's birthdays? How can you come back to that list and know which date matches which birthday? This is done in PHP, and in most programming languages, by using the concept of variables. The final part of the chapter will be spent looking at variables and how we can use them to perform mathematical operations, or simple manipulations of text.

The itinerary for this chapter is:

  • Write and examine a very short PHP program

  • Discuss some of the Internet Protocols

  • Talk about the role of the PHP engine and the web server

  • Define what we mean by interpretation and execution

  • Variables - what are they?

  • Data Types - we will discuss the different data types that variables can have

  • Operations you can perform on variables

  • Constants

  • Converting variables from one data type to another

  • Environment variables
An Example PHP Program

This chapter starts with almost the simplest one line example possible - we aim to demonstrate that PHP pages are a mixtures of three things, namely text, HTML code, and PHP script. Pages containing PHP script are different from pages that contain only HTML, and in order to identify them to the PHP engine, they are saved with the .php suffix (or something similar) on the web server and are executed by the PHP engine running on the server.

The .php suffix is something that is dependent on your particular configuration of PHP. If you wanted to, when setting up PHP, you could change it to almost anything, even something like .groovysuffix. In this book we will be using the suffix .php in lower case only.

The results of this are returned to the browser in HTML. We'll see more on this shortly, but let's get started on an example.

Try It Out - First Example Program

Open your web page editor of choice and type the following:

<HTML>
<BODY>
The date at the moment is
<?php echo gmdate("M d Y");
?>
</BODY>
</HTML>

Save this as example1.php in the document root (on UNIX systems) or root directory (on Windows systems) of your web server.

Next, open up your browser of choice, type in the full URL of your web server and web page, mine would be http://chrisu/example1.php. You should see something similar to the following in Navigator 6:




PAGE: 1 I 2 I 3 I 4 I NEXT PAGE
 





Ready to take that job and shove it?

Function:

Keyword(s):

State:
SPONSOR
RECENT JOB POSTINGS
CAREER NEWS
Go beyond Google and get vertical. These specialized search sites will help you find the business information you need -- fast.

Ari Balogh was named to the post of chief technology officer as the companys for a "realignment" of employees.










InformationWeek U.S. IT Salary Survey 2008
Salaries for business technology professionals are falling. Here's what you need to know in order to make good hiring decisions and personal career choices. Purchase Today: $299
 
ROLLING RIGHT ALONG
Follow key Network Computing Reviews from conception to completion. This Week: Holistic APM.



Network Computing Reports Emerging Enterprise Podcast Series: Secrets to Success








TechSearch


Microsite of the Week


Powerful Information at Your Fingertips



App Infrastructure   |   Messaging & Collaboration   |   Network & Systems Mgmt   |   Network Infrastructure   |   Security  |   Storage & Servers   |   Wireless   |   Enterprise Apps
About Us  |  Contact Us  |  Site Map  |  Media Kit  |   Briefing Centers
Other Techweb Sites:   InformationWeek Reports  |  Intelligent Enterprise  |  Light Reading  |  InformationWeek
Techweb  |  Dark Reading  |  Network Computing Germany  |   Byte & Switch  |  bMighty  |  Small Biz Resource  |  InformationWeek Analytics
Copyright © 2008  United Business Media LLC  |  Privacy Statement  |  Terms of Service  |  Your California Privacy Rights