HAL-PC Scheduled Classes TWiki > Classes > IntroPHP1 TWiki webs:
AIX| Classes | HALBOD | HLUG | Helpdesk | Library | Main | Samba | TWiki |
Classes . { TWikiGuest | Index | Changes | Search | Go }
Houston Area League of PC Users Education System <BODY BGCOLOR="#e2e3ed" TEXT="#07070a" LINK="#777bb4" ALINK="#777bb4" VLINK="#777bb4">
php logoPHP stands for PHP: Hypertext Preprocessor.
http://www.php.net
A computer program consists of a set of instructions that the computer understands. Most computers without programs do absolutely nothing.
The instructions in a computer program are in machine code; they are usually originally written in a computer programming language, and translated to machine code using a computer program called a compiler or an interpreter.
Scripting programming languages are computer programming languages designed for "scripting" the operation of a computer.
PHP is a widely-used, open source, server side, scripting language that is especially suited for Web development and can be embedded into HTML.
Because PHP is executed on the server:
1) the client (browser) cannot view the PHP code.
2) your web host will need to have PHP set up on their server.
3) your users will not need to install new software
4) you do not need to worry about compatibility issues beyond those issues presented by browser incompatabilities.
To see how this works we will look at one simple PHP function:
phpinfo()
This will actually be your first PHP Program in this class.
HAL-PC's HALNet Internet Service does run PHP on it's Web Server.
Each of you has a login and web space on that server for the duration of this class.
Those of you that are HALNet Clients have always had web space on that server and you may do your classwork in your own home page web space if you prefer.
It is better not to use a word processor like MS Word or WordPerfect? to write your PHP Scripts.
Word Processing Programs are written to format your text and will insert special characters into your text that the PHP interpreter on the server will have difficulty understanding.
Please open notepad on your computer:

* From the Start menu, select Programs
* From the Accessories menu, select Notepad


The Notepad window is displayed.
The first thing we must do is tell the server that this is PHP and not HTML.
Your PHP scripts will normally be embeded in HTML.
If you have questions about HTML you might want to consider attending HAL-PC's Webmaster, Marilyn Wright Gore's, Introduction to HTML Class. There is a class scheduled to begin next week on September 22nd at 7pm.
There are PHP start tags or HTML escape tags, one of which must be used to denote where you have placed your blocks of PHP code.
You may tell the computer that this is PHP script by typing the preferred and most used php start tag:

<?php
A function is a named section of a program that performs a specific task.
Most programming languages come with a prewritten set of functions that are kept in a library. You can also write your own functions to perform specialized tasks.
Our first PHP script will rely heavily on a predefined PHP function
Please enter the following PHP function into your text file:

phpinfo()

For the complete list of documented PHP Functions go to: http://www.php.net/quickref.php
We will not cover all of PHP's documented functions in this class. Even if we did try to cover every single documented function we would miss newer functions that have not been documented yet. Since PHP is Open Source there is a worldwide community of programmers developing the language all of the time. We will acquire the tools we need to do our own research and development. What you learn in this class should be applicable to almost any programming language you choose to learn in the future.
Syntax can be thought of as the rules for writing a program.
PHP is a C-style language. This means that much of its syntax is similar to C. If you are familiar with most any C-style language (C, C++, Java, JavaScript?) then PHP should look very familar.
An example of PHP syntax is:

Every statement must end in a semi-colon ( ; ). The semi-colon is the programmatic equivalent of the period at the end of the sentence.

We will end our call to the PHP predefined function phpinfo with a semi-colon ( ; ).

phpinfo();
We now have a file that looks like this:

<?php
phpinfo();
We need to tell the PHP interpreter on the web server that this is the end of this block of PHP code.
We will do this by adding:

?>

The closing tag for the block will include the immediately trailing newline if one is present. Also, the closing tag automatically implies a semicolon; you do not need to have a semicolon terminating the last line of a PHP block. Closing tag of a PHP block at the end of a file is optional.
Our first php script now looks like this:

<?php
phpinfo();
?>
There is one more thing we need to do to tell the Web Server that this file contains PHP.
We will save the file with .php as the extention.
Please save your file in c:/windows/temp as info.php
To prevent the .txt extension being appended to your saved file name, enclose the filename in quotation marks: "info.php", when typing it into the Save As dialog box.
In order to run our PHP script we will have to place it on the web server where we have the PHP interpreter running.
Windows 2000: click Start, then Run, and then type: cmd.exe and click OK.

> c:

> cd windows/temp

> ftp www.hal-pc.org

220 delphi.hal-pc.org FTP server (Version 6.00LS) ready.
Name (www.hal-pc.org:anne): phpx
331 Password required for phpx.
Password: phpx
230 User phpx logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
150 Opening ASCII mode data connection for '/bin/ls'.
total 30
drwxr-xr-x 8 phpx operator 3072 Sep 11 16:16 public_html
-rw-r--r-- 1 phpx operator 229 Sep 11 16:26 quota
226 Transfer complete.
ftp> cd public_html
250 CWD command successful.
ftp> put info.php
local: info.php remote: info.php
150 Opening BINARY mode data connection for 'info.php'.
100% |**************************************************| 1444 00:00 ETA
i 226 Transfer complete.
1444 bytes sent in 0.05 seconds (30.82 KB/s)
ftp> chmod 755 .
ftp> bye
221 Goodbye.
Open a browser on your computer.
In the location bar enter the URL:
http://www.hal-pc.org/~phpx/info.php
There's a lot of information displayed here that we certainly didn't type into our little php script.
Let's see how the page source looks to the browser.
Please open the view page source window on your browser.
As you can see PHP executed on the web server and delivered only HTML to the browser.
You can also see the tremendous power available to the developer using PHP predefined functions.
So, our new problem is how do we get PHP to display what we want it to display in our clients web browser.

Next     Next!


-- RickArchibald - 17 Sep 2004

Topic IntroPHP1 . { Edit | Attach | 5B%5EA-Za-z%5D">Ref-By | Printable | Diffs | r1.1 | More }
Revision r1.1 - 17 Sep 2004 - 04:02 GMT - RickArchibald Copyright © 2003-2007 by F. A. Archibald III & the contributing authors