| [main] [misc] [graphics] [page design] [site design] [xhtml] [css] [xml] [xsl] [schema] [javascript] [php] [mysql] | |
Note that all external links will open up in a separate window. This is a stripped down version of these pages for older browsers. These pages are really meant to be viewed in a standards compliant browser. |
Hello WorldHello WorldEvery programming language must have a Hello World exercise right at the very beginning of any form of instruction related to it. I am almost positive that this is inscribed in a mystical tome of computer science instructional guidelines somewhere. In any event, the objective of this exercise is to introduce you to the language and help you to develop a basic familiarity with using PHP on the context of Web documents. In order to do this exercise, you are going to have to save the document to a directory accessible to a Web server that runs PHP. We will call this directory, your Web directory. It may be local, or it may require that you load your page out to a Web server somewhere. This depends on whether or not you have a test server with PHP running on the machine you are working on. PHP runs as a process on an HTTP server, so you can't read PHP documents as normal files. Well, you can, but you will get the code instead of the results of the code, which is probably not what you wanted. Step 1: Hello World
Step 2: Adding some PHPOkay, so we have the XHTML shell and now need to add the PHP. PHP gets included inside SGML-style processing directives. processing directive: a command directly addressed to the program processing the code to give it instructions on how to do so All processing directives begin with an open bracket and a question mark, and end with a question mark and closing bracket. Within the brackets go the name of the application being passed instructions to and the instructions to be passed. If the name of the application is included, it must come immediately after the question mark, just like and HTML or XML tag. <?appname some instructions ?> We already have one example of this in the XML version declaration statement above.
The XML version declaration also used the processing directive format. However, some servers may have a PHP system variable called Next we are going to do is add a piece of script that reads the information from the form when loading the page.
Wait, you may ask, if it processes the information before sending the page, how can it process information the user hasn't entered yet? The answer is, it can't. But it can look at the information send to it when someone fills in the form field and then clicks submit, which if you look at the
Step 3: Look at It
ExplanationWhat happened in this exercise?
When we submit our form it submits the information from the form back to the server. If you remember how forms work, they send a collection of name value pairs involving the
The PHP parser recieves the information from the form formatted into an array. If we use
The index values for the array are the names of the fields in the form. Our field was named "namefld", therefore, the array element we are looking for is By the way, be careful with single and double quotes in PHP. They do different things.
These pages can be found at:
[http://academ.hvcc.edu/~kantopet/]
|