HTML (HyperText Mark-up Language) is the language browsers use on client-side computers to display web pages. PHP is a Hypertext Preprocessor; a programming language on the server that creates HTML to add to the page before it is sent back to the client machine.
A PHP parser resides on a server. When the server receives a request for a web page with any PHP on it at all, the entire page is sent to the PHP parser, the PHP code is run and HTML is returned to the server. When the server is finished with its own processing, the entire HTML bundle is sent back to the requesting client computer. The client machine never sees the PHP code, only the resulting HTML. (This all happens in the blink of an eye.) This is typical of all server-side programming languages.
To tell the server there is PHP code in your program, you must use a file-naming convention of '*.php'. Without this extension, the server doesn't know to first send the page to the PHP parser.
For PHP code to work, the file must reside on a server, and that server must have a PHP parser. Most computers available to you do not have these combinations. Thus, you can not design a web page with PHP coding in it on your office computer and expect it to display, unless you first install PHP. For this course, I will assume you have PHP on your desktop, or within your LAN, or via FTP, or something. You must load all your work into a directory that will run PHP.
Open a new HTML file in your favorite HTML editor, (I use HTML-Kit), and add the code shown below in blue (hint: you can cut from below and paste in your own file):
Now save the file in your site folder using some name you will remember (like test.php or something similar), and open it in your browser. You should see something like this:
You just used the echo command and the date function. Echo tells the PHP parser to convert whatever follows into HTML and display it on the screen. The date function reads today's date and formats it in whatever way you like; in this case it is formatted to show the day of the month first, then the name of the month, then the year. The dynamic nature of this function is that whenever this page is displayed, it will show whatever the server considers to be the current date.
Note how the PHP code is identified. Anything written between <php and ?> is interpreted as PHP code. Thus, you can add dynamic content wherever you like in your file.
A single statement of code in PHP ends with a semi-colon ( ; ). "Statements" of PHP code can be written on the same line--they must just each end in semi-colons. As in HTML, PHP ignores whitespace and allows for comments:
displays:
The URL for this page is: http://sandersongs.com/PHPsqlCourse/PHP01.php
If you reference the footer below and to the right, you will see this code in action. It is repeated on all pages of this tutorial.