Chapter 0:Introduction 0-000.000 - About This Course
Chapter 1:PHP Basics 1-1.1 - Hit the ground running.
1-1.2 - A Simple PHP Program
1-1.3 - Formatting the code
1-1.4 - Comments in PHP
1-1.5 - Storing Data in Variables
1-1.6 - The print() Function
|
Chapter: 1 - PHP Basics
Lesson: 1.2 - A Simple PHP Program
Yes, I know. It is a little cliche, but you can't have a tutorial or book on any programming language without seeing the words "Hello World" appearing in the first chapter. So, we are going to write a simple program to be embedded within an HTML page which outputs the phrase, "Hello World" and gives the date from the server.
For now, don't focus on how the date formatting and stuff works at this point, we'll get to that later on. Just know that it works. But, I want you to see how PHP is integrated with HTML. There are a number of ways to do this and so to learn, I have selected the simplest method.
Notice, in figure 1.2, the PHP code starts at the tag that is expressed as and ends at the tag . This is how the server knows what code to process in PHP and what code to pass on to the user's browser for processing.
Figure 1.2, a simple PHP program. (download code here)
(Click Here to try the sample code)
From this example we can see, that PHP and HTML reside together quite happily. You can choose to pop your PHP tags in to perform a server-side function (such as displaying the date as in this example) or use php to output HTML (like we did to display the text "Hello World".
Of course, the output of the words "Hello World" could more easily be performed in a static HTML environment. But, imagine if you needed a unique salutation depending on the user's browser, or IP address, then you can see the usefulness of PHP.
|