PHP – An Introduction
Made By: Anuj Puranik 5th Sem CSE,NIIST Bpl
Agenda
1. Brief History of PHP
2. Getting started
3. Examples
Brief History of PHP
PHP (PHP: Hypertext Preprocessor) was created by Rasmus Lerdorf in 1994. It was initially developed for HTTP usage logging and server-side form generation in Unix. Officially called "Personal Home Page Tools
(PHP Tools)". This is the first use of the name "PHP".
PHP 2 (1995) transformed the language into a Server-side embedded scripting language. Added database support, file uploads, variables, arrays, recursive functions, conditionals, iteration, regular expressions, etc.Considered by its creator as the "fastest and simplest tool" for creating dynamic web pages . PHP 3 (1998) added support for ODBC data sources, multiple platform support, email protocols (SNMP,IMAP), and new parser written by Zeev Suraski and Andi Gutmans. Development moves from one
person to multiple developers
PHP 4 (2000) became an independent component of the web server for added efficiency. Added more advanced two-stage parse/execute tag-parsing system called the Zend engine. . Many security features were added. PHP 4.1-4.3 (2001-02) Introduced the superglobals ($_GET, $_SESSION, etc.) , Disabled register_globals by default PHP 5 (2004) adds Zend Engine II with object oriented programming, robust XML support using the libxml2 library, SOAP extension for interoperability with Web Services, SQLite has been bundled with PHP PHP 5.2.4 (2007) Enabled the filter extension by default released on 30 August 2007. It is considered to be free software by the Free Software Foundation.
Brief History of PHP
As of August 2005, PHP is used on 23,946,328 Domains, 4,348,793 IP Addresses http://www.php.net/usage.php This is roughly 48% of all domains on the web.
What is PHP ?
PHP is a reflective programming language originally designed for producing dynamic web pages.PHP is used mainly in server-side scripting, but can be used from a command line interface or in standalone graphical applications. Textual User Interfaces can also be created using ncurses. PHP is a recursive initialism for PHP: Hypertext Preprocessor.
In Other Words, PHP is a scripting Language generally used for web Developments which has a combined traces a Progaramming Language and a web-dev language PHP is Influenced by C/C++, Perl, Python ,Java
Why is PHP used?
1. Easy to Use
Code is embedded into HTML. The PHP code is enclosed in special start and end tags that allow you to jump into and out of "PHP mode".
Example
Why is PHP used?
2. Cross Platform
Runs on almost any Web server on several operating systems. One of the strongest features is the wide range of supported databases
Web Servers: Apache, IIS(Microsoft Specific), Caudium, Netscape Enterprise Server Operating Systems: UNIX (HP-UX,OpenBSD,Solaris,Linux), Mac OSX, Windows NT/98/2000/XP/2003 Supported Databases: Adabas D, dBase,Empress, FilePro (readonly), Hyperwave,IBM DB2, Informix, Ingres, InterBase, FrontBase, mSQL, Direct MS-SQL, MySQL, ODBC, Oracle (OCI7 and OCI8), Ovrimos, PostgreSQL, SQLite, Solid, Sybase, Velocis,Unix dbm
Cross Platforms Architecture
Some of the Common & Cost Beneficial Architectures are 1.LAMP Linux,Apache,MySQL,Php 2.WAMP Windows,Apache,MySQL,Php 3.MAMP MacOS,Apache,MySQL,Php XAMP An OS,Apache,MySQL,Php
Why is PHP used?
3. Cost Benefits
PHP is free. Open source code means that the entire PHP community will contribute towards bug fixes. There are several add-on technologies (libraries) for PHP that are also free.
PHP
Software
Platform Development Tools
Free
Free (Linux) Free PHP Coder, jEdit
Why is PHP used?
4. Scripting/Programing Language(C-Like)
Since writing a PHP is more or less like a programming Language hence its often easy for the programmers to grab the control in a short while when working in a PHP environment. Hence PHP is now becoming a Programmer’s 1st Choice
5. Fast ,Stable ,No Compilation
Since PHP is a Server Side Scripting, hence no additional Plug-ins are required to view the output.
6. Extremely Powerful
Easy Use ,Vast Functionality, Wide Applications and Add-ons like PHPmyadmin makes PHP Extremely powerful Web-dev tool as compared to other languges.
Getting Started
1. How to escape from HTML and enter PHP mode
• PHP parses a file by looking for one of the special tags that tells it to start interpreting the text as PHP code. The parser then executes all of the code it finds until it runs into a PHP closing tag.
HTML
PHP CODE
HTML
Starting tag
Ending tag
?>
?> ?>
Notes
Preferred method as it allows the use of PHP with XHTML
Not recommended. Easier to type, but has to be enabled and may conflict with XML Always available, best if used when FrontPage is the HTML editor Not recommended. ASP tags support was added in 3.0.4
<%
%>
Getting Started
2. • Simple HTML Page with PHP The following is a basic example to output text using PHP.
My First PHP Page
Copy the code onto your web server and save it as “test.php”. You should see “Hello World!” displayed. Notice that the semicolon is used at the end of each line of PHP code to signify a line break. Like HTML, PHP ignores whitespace between lines of code. (An HTML equivalent is
)
Getting Started
3.
•
Using conditional statements
Conditional statements are very useful for displaying specific content to the user. The following example shows how to display content according to the day of the week.
Getting Started
3.
•
•
Using conditional statements
The if statement checks the value of $today_dayofweek (which is the numerical day of the week, 0=Sunday… 6=Saturday) If it is equal to 4 (the numeric representation of Thurs.) it will display everything within the first { } bracket after the “if()”. If it is not equal to 4, it will display everything in the second { } bracket after the “else”.
Examples
• PHP is a great way to implement templates on your website. • How to implement a simple page counter
Examples
•
•
Step 1: Universal header and footer in a single file
Create a file called header.php. This file will have all of the header HTML code. You can use FrontPage/Dreamweaver to create the header, but remember to remove the closing