HISTORY of PHP:
- PHP was written in the C programming language by Rasmus Lerdorf in 1994 for use in monitoring his online resume and related personal information. For this reason, PHP originally stood for “Personal Home Page”.
- Two programmers, Zeev Suraski and Andi Gutmans, rebuilt PHP’s core, releasing the updated result as PHP/FI 2 in 1997. (Name changed to PHP: HyperText Preprocessor ).
- In 1998, PHP 3 was released, which was the first widely used version.
- PHP 4 was released in May 2000, with a new core, known as the Zend Engine 1.0.
- PHP 5 was released in July 2004, with the updated Zend Engine 2.0. Among the many new features in PHP 5 are:
1. improved object-oriented programming
2. embedded SQLite
3. support for new MySQL features
4. Exception handling using a try..catch structure
5. the Filter library (in PHP 5.1)
6. better XML tools
7. PHP 6 has been developed in October of 2006.
What is PHP?
- PHP is a server-side scripting language.
- PHP stands for PHP: Hypertext Preprocessor
- PHP is a server-side scripting language, like ASP,JSP means it executed on server.
- PHP is an open source language
- PHP runs on different platforms (Windows, Linux, Unix, etc.)
- PHP is compatible with almost all servers used today (Apache, IIS, etc.)
- Powerful, Robust, scalable.
FEATURES OF PHP
- PHP stands for 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.
- It is an interpreted language.
- There are three main fields where PHP scripts are used.
1. Server side scripting
2. Command line scripting.
3. Writing client-side GUI applications. For this PHP-GTK is used.
— PHP-GTK is an extension for the PHP programming language that implements language bindings for GTK+. It provides an object-oriented interface to GTK+ classes and functions and greatly simplifies writing client-side cross-platform GUI applications.
- PHP can be used on all major operating systems, including Linux, many Unix variants, Microsoft Windows, Mac OS X etc.
- PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server and many others.
- You also have the choice of using procedural programming or object oriented programming, or a mixture of them.
- PHP does more than just generating dynamic web-pages.
- PHP’s abilities includes:
1. Generating images dynamically
2. PDF files
3. Flash movies
5. Download and upload
6. XML support
- PHP also has support for talking to other services using protocols such as LDAP (Light-Weight Directory Access), IMAP(Internet Message Access Protocol), SNMP(Simple Network Management Protocol), NNTP(Network News Transfer Protocol), POP3, HTTP, COM (on Windows) and countless others.
- You can also open raw network sockets and interact using any other protocol.
- PHP has support for the WDDX(Web Distributed Data eXchange) complex data exchange between virtually all Web programming languages. (Support for web services)
- PHP has support for instantiation of Java objects and using them transparently as PHP objects. You can also use CORBA extension to access remote objects.
e.g. You can use java classes in php.
- Web servers are computers that deliver (serves up) Web pages.
- Every computer on the Internet that contains a Web site must have a Web server program.
- Two leading Web servers are Apache, the most widely-installed Web server, and Microsoft’s Internet Information Server (IIS).
- is a powerful, flexible, HTTP/1.1 compliant web server
- implements the latest protocols, including HTTP/1.1
- is highly configurable and extensible with third-party modules
- can be customized by writing ‘modules’ using the Apache module API
- provides full source code and comes with an unrestrictive license
- Quick PHP
- File extension Should be .php
- Index.php file is executed first
- You Require a Wamp Server to run php File
- All the PHP Files Should be in the WWW directory of wampserver
- Goto Local Host then Find your Application and Run it
PHP code must be contained in special tags so that the PHP interpreter can identify it. Depending on the PHP configuration, these tags can take several forms:
|<?phpPHP CODE GOES IN HERE?>||This is the most commonly used (and recommended) form. It is known as the XML style, because it can be used inside of an XML document without causing the document to become poorly formed.|
|<script language=”php”>PHP CODE GOES IN HERE</script>||HTML or Script style tags.|
|<?PHP CODE GOES HERE?>||“Short” tags.|
|<%PHP CODE GOES HERE%>||ASP-style tags.|
In this manual, we will use the first form shown as it is the most common and the most portable.
- Variables are used for storing a values, like text strings, numbers or arrays.
- When a variable is declared, it can be used over and over again in your script.
- All variables in PHP start with a $ sign symbol.
- And echo is used for Printing.
<?php $temp=10; echo $temp; // outputs "10" ?>
Naming Rules for Variables
- A variable name must start with a letter or an underscore “_”
- A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )
- A variable name should not contain spaces. If a variable name is more than one word, it should be separated with an underscore ($my_string), or with capitalization ($myString)
How PHP Is Parsed?
- The Web browser requests a document with a .php extension to the web-server.
- After receiving the request Web server sends the request on to the PHP parser.
- The PHP parser finds the requested file and scans it for PHP code.
- When the PHP parser finds PHP code, it executes that code and places the resulting output (if any) into the place in the file formerly occupied by the code.
- This new output file is sent back to the Web server.
- Webserver converts it in to HTML and send it to Web Browser as a response.
- The Web browser displays the output.
How PHP Works?
When a user navigates in her browser to a page that ends with a .php extension, the request is sent to a web server, which directs the request to the PHP interpreter.
As shown in the diagram above, the PHP interpreter processes the page, communicating with file systems, databases, and email servers as necessary, and then delivers a web page to the web server to return to the browser.
Comments in PHP
// single line comment /* Multi line comments */ <?php // echo “Hello India” /* $a=10; $b=20; echo $a+$b; */ ?>