What is PHP?

PHP stands for "PHP: Hypertext Preprocessor". It is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. PHP allows you to create dynamic, interactive Web-based applications such as customized web pages, "shopping carts", session tracking with "cookies", database management, and other interactive Web-based applications which communicate information between the client-side (your computer and browser) and the server-side (your Web server).

PHP is a programming language, somewhat similar in its structure and appearance to JavaScript, C++, and Perl. Both JavaScript and PHP instructions can be embedded within the HTML instructions. However, PHP differs from JavaScript in some significant ways:

PHP also differs from C++ and Perl in one significant way, in that PHP instructions are generally placed in the Web page file along with the HTML tags. In other words, the PHP is embedded within the web page. In contrast, programs written in C++ or Perl, are completely separate program files residing on the server.

Any program (also known as a script), which executes within the Web server and responds to and processes input provided by the viewer, is broadly referred to as a CGI (Common Gateway Interface) script. So, PHP, C++, and Perl are used to accomplish the same sorts of tasks.

Because PHP executes completely within the Web server, there are several important considerations:

To find out if you have PHP on your Web server, try this simple PHP program with these steps.

  1. Click on the link above to display the file. (It has been named with a .txt extension so as not to launch automatically when you click on the link.)
  2. Download the file to your computer by clicking on "File", and "Save As...". Note: Change the file extension from .txt to .php then click on the "Save" button.
  3. Verify that the saved file is now named "doihavephp.php", and then upload it to your Web account directory as you would any web page.
  4. Try to open the file via your favorite browser. If you see "Congratulations! You have PHP.", you're in business! Consult your Web server administrator for specific details.

As mentioned above, PHP is a natural-text, computer programming language that can be placed directly into the HTML file. It is an interpreted language; which means it is executed automatically by the built-in PHP interpreter within the Web server. It does not end up as an additional file to be downloaded, as does a Java applet.

What is PHP made of?

PHP is a full-featured programming language which can can manipulate both simple "scalar"(single-value) or object-oriented data structures. An object is an entity (eg. a database, a record, a field) that can be treated as an individual unit or component. Relating this to Web pages, entities within the Web page can be accessed, read, and have their values determined by PHP instructions. Entities within a Web page which can be named (or are named implicitly), are accessible by PHP.

The major Web page entities accessible by PHP include:

Objects have attributes (also called "properties"), which are attached to the object with a "->" construct (eg. room->length and $room->$width).

In addition to attributes, PHP objects may also have "functions" (a sequence of programming instructions producing something specific) associated with them. For example, if a room is defined as an object, with attributes "$length" and "$width". The floor space area of the room could be a function using length and width as parameters. The floor space function could be written as
function floor_space($length,$width) {
$this->floorspace = $length * $width;}
and calculated for a specific room instance with the statement
$my_room->floor_space(10,12);
and printed in the Web page with
print("<p>",$my_room->floorspace,"/p");

References:

PHP 4Bible, Tim Converse and Joyce Park, Hungry Minds, Inc.
PHP Professional Projects, Ashish Wilfred, Meeta Gupta, and Kartik Bhatnager, Premier Press.


Return to the PHP examples.