About Website Source / Network

 

Website Hosting Guides - Using PHP

Tutorials

PHP – Overview

On this page:

PHP or the Hypertext Preprocessor is an open source, server-side; HTML embedded scripting language. Primarily used for creating dynamic web pages, PHP saw daylight as a small set of Perl scripts followed by a rewritten set of CGI binaries written in C.

PHP

 

Quick Facts:


  • Full Form: Hypertext Preprocessor
  • Maintainer: The PHP Group
  • Latest release: 5.1.2 / January 12, 2006
  • 4.4.2 / January 13, 2006
  • OS: Cross-platform
  • Genre: Scripting language
  • License: PHP License 3.01
  • Website: www.php.net

A Brief History

Credits for inventing PHP goes to a Danish-Canadian programmer named Rasmus Lerdorf, who used it in 1994 for displaying his résumé and for tracking the traffic in his website. Personal Home Page Tools was commercially released on 8th June 1995. The public version was a combination of the actual PHP and Lerdorf’s own Form Interpreter that was named PHP/FI.

Further Developments

Credits for re-writing the parser (a computer program that divides code up into functional components) go to Zeev Suraski and Andi Gutmans, two Israeli developers of the Technion - Israel Institute of Technology. 1997 saw the base of PHP 3 getting formed. The name of the language also underwent a change; it is at this point the recursive acronym PHP: Hypertext Preprocessor was introduced. PHP/FI 2 was officially released in November 1997 and the official launch took place in June 1998. PHP's core was then re-written for producing the Zend engine (1999) and in May 2000, PHP 4, powered by the Zend Engine 1.0, was released. July 13, 2004 witnessed the release of PHP 5 (powered by Zend Engine 2.0), which included new features such as PHP Data Objects (PDO) and an enhanced performance altogether.

The way PHP handles objects has undergone drastic changes, with better performance and more features being the enhancements. Now php references objects by handle, and not by value.

Other developments are as follows:

  • PHP 5 introduces private and protected member variables to define the visibility of class properties.
  • Private and Protected Methods.
  • PHP 5 has introduced abstract classes and abstract methods, the latter only declares the method's signature but does not provide an implementation. A class that contains abstract methods needs to be declared an abstract class and also may implement an arbitrary list of interfaces.

PHP: The Inside Story

The Initials

PHP, the initials point to the earliest version of the program or the Personal Home Page Tools. Their current form constitutes a recursive acronym and is an open-source, reflective programming language used mainly for developing server-side applications and dynamic web content, apart from a broader range of software applications.

Functionalities

PHP is capable of interacting with a large number of relational database management systems. Examples include MySQL, Oracle, IBM DB2, Microsoft SQL Server, PostgreSQL, Firebird and SQLite. Also capable of running on most major operating systems (Unix, Linux, Windows, Mac OS X), PHP can interact with many major web servers using IMAP, SNMP, NNTP, POP3, or HTTP. The prime features of PHP are the command line interface (CLI), apart from the GUI libraries (Gimp Tool Kit/GTK+) and text mode libraries (Ncurses and Newt).

A PHP script, being of a similar syntax to that of Perl or C, is usually enclosed within special PHP tags in a HTML document. The embedding allows the author to jump between HTML and PHP just like in the cases of ASP and Cold Fusion. The need for bulk amount of code to output HTML is thus minimized. PHP, being executed on the server, blocks the client from viewing the PHP code.

PHP: The object-oriented features

PHP started including object-oriented features from version 3 onwards. Though it was only basic object functionality, the semantics were implemented in PHP 4 as pass-by-reference and return-by-reference for objects. The implementation, however, lacked the power and versatility of other object-oriented languages like C++ and Java. Version 5, released in July 2004, saw PHP's object-oriented functionality enhanced in a much more robust and complete form.

Using PHP

The Reasons

    • Web pages, pictures and text aside, use a lot of animation and/or interactivity nowadays; features like discussion forums, searches and/or shopping carts have currently become abundant. PHP enables adding these features with much ease and requires lesser time than the old fashioned CGI scripts in Perl used to take. CGI scripts, being less scalable by nature, require the server to start a new process in the kernel upon each new request. CPU time and memory are the main resources that suffer, thus slowing down the execution of multiple concurrent CGI scripts.  PHP, on the other hand, becomes a part of the Web server and reduces the load time.
    • PHP is an open source project that is platform independent. It allows users to download both the source code and executables and install them on their computer for free. 
    • Learning PHP is easy. Knowledge in C or Perl is an added advantage, since PHP combines the best features from both. Solving common problems becomes easy because of its enhanced features. Examples include embedding PHP code directly into an HTML file (with Perl and C, additional print statements to output HTML is must).  PHP has a native database support for 12 databases including mSQL and mySQL. This enables access to the databases directly through SQL statements.

Applications

  • The LAMP architecture: The web industry has embraced Linux, Apache, MySQL and PHP because they allow deploying inexpensive, reliable, scalable and secure web applications.
  • An alternative to popular systems: The PHP model is currently  

being looked at as an alternative to Microsoft's ASP.NET/C#/VB.NET system, Macromedia's ColdFusion system, Sun Microsystems' JSP/Java system, the Zope/Python system, the Mod Perl/Perl system. PHP is also being held an alternative to the more recent Ruby on Rails framework.

How PHP Works

Let’s call PHP basic html with advanced preprocessing features. The HTTP protocol transfers hypertext (Machine-readable text that is not sequential but is organized so that related items of information are connected), while PHP acts as a phase that pre processes the documents before they reach the client. PhP documents require a PHP enabled/installed server to function. A Linux server always has PhP installed and working; else, it can be installed from http://www.php.net.

php parsing

Processing of php documents

Data types

      • Arrays: Heterogeneous by nature, an array contains objects of multiple types that PHP can handle, including resources, objects, and even other arrays. Arrays are used as ordered lists of only values and as hashes with keys and values, either singly or simultaneously. When used as hashes (associative arrays), the ordering of keys is preserved.

Representation:

 

$myArray = array('key 1' => 'string value 1', 2005, new StdClass(), array("I", "love", “arrays"))

 

      • Strings: Double quotation marks (") evaluate variables, but not the single quotation marks ('). Functions and other expressions are not evaluated inside double quotes. They are instead added to strings using periods for concatenation (union in a linked series).

Representation:

 

$myString = 'string' . myFunction() . 'rest of string';

$myString = "string{$myArray['key 1']}rest of string";

      • Boolean: PHP has a native Boolean type, named "boolean", the variables of which consist of two possible values, True and False. Similar to the native Boolean types in Java and C++, the boolean differs from the approach used by Perl and C. The non-zero values are interpreted as true while zero values are interpreted as false.

Representation:

$myBoolean = True; $myBoolean = False;

      • Integer: The Integer type is a platform-dependent range that stores whole numbers or 32-bit integers. Integer variables can be assigned using decimal (positive and negative), octal and hexadecimal notations.

Representation:

$decimal = 1234; // decimal number

$negative = -123; // a negative number

$octal = 0123; // octal number (equivalent to 83 decimal)

$hexadecimal = 0x1A; // hexadecimal number (equivalent to 26 decimal)

 

      • Floating Point Numbers: The Floating point type stores Real numbers in a platform-specific
        range and is specified using floating point / two forms of Scientific notation.

Representation:

$float = 1.234;

$float = 1.2e3;

$float = 1E-23;

      • Null: The Null data type represents a zero value variable(NULL).

Representation:

 

$null = NULL;

Simple PHP Coding

You can use PHP tags and HTML tags together. But the PHP tags can be read by the program if the PHP recognition command is provided. PHP parser, on the server, shall parse php only upon receiving the command:

<?php
code any word
?> 

Anything within the parentheses shall be parsed; the rest shall simply be sent directly to the client. The apache configuration file allows deciding on what file extensions shall parse though php.

N.B. If php allot is used, .html and .htm can be added to put php code in an .htm/.html file to parse it.

<?php
echo("Test Text"); //first comment

/* second comment */

?>

Upon uploading this code to a server and then opening it shall give the text Test Text. The first comment shows the way to add further comments to the code and is a single line comment. The second comment is to be used for longer comments that are more then one line.

 

Note: All Content Copyright © Website Source, Inc.

Footer Image



Login


Website hosting customer feedback

Sanaz was very friendly and helpful to me with regards to my technical issue. THUMBS UP TO HER!!! :)

Steve

read more