Вы находитесь на странице: 1из 23

Developing Web Applications with PHP

By Paras Bhatt

Agenda
Introduction PHP Language Basics Built-in Functions Tricks and Tips PHP 5

Introduction
What is PHP?
PHP stands for "PHP Hypertext Preprocessor An embedded scripting language for HTML like ASP or JSP A language that combines elements of Perl, C, and Java

Introduction
History of PHP
Created by Rasmus Lerdorf in 1995 for tracking access to his resume Originally a set of Perl scripts known as the Personal Home Page tools Rewritten in C with database functionality Added a forms interpreter and released as PHP/FI: includes Perl-like variables, and HTML embedded syntax

Introduction
History of PHP (cont.)
Rewritten again in and released as version 2.0 in November of 1997 Estimated user base in 1997 is several thousand users and 50,000 web sites served Rewritten again in late 1997 by Andi Gutmans and Zeev Suraski More functionality added, database support, protocols and APIs

Introduction
History of PHP (cont.)
Rewritten again in 1997 by Andi Gutmans and Zeev Suraski More functionality added (OOP features), database support, protocols and APIs PHP 3.0 is released in June 1998 with some OO capability The core is rewritten in 1998 for improved performance of complex applications

Introduction
Netcraft Statistics
11,869,645 Domains, 1,316,288 IP Addresses

Introduction
Performance*
Statistics
PHP pumped out about 47 pages/second Microsoft ASP pumped out about 43 pages/second Allaire ColdFusion pumped out about 29 pages/second Sun Java JSP pumped out about 13 pages/second
* From PHP HOWTO, July 2001

PHP Language Basics


The Script Tags
All PHP code is contained in one of several script tags:
<? // Some code ?> <?php // Some code here ?>

PHP Language Basics


Hello World!: An Example
Like Perl, there is more than one way to do it, But the main used is in the example below
<?php echo Hello World!; ?> Save the file by .php extension

PHP Language Basics


Constants, Data Types and Variables
Constants define a string or numeric value Constants do not begin with a dollar sign Examples:
define(COMPANY, Acme Enterprises); define(YELLOW, #FFFF00); define(PI, 3.14); define(NL, <br>\n);

PHP Language Basics


Constants, Data Types and Variables
Using a constant
print(Company name: . COMPANY . NL);

PHP Language Basics


Constants, Data Types and Variables
Data types
Integers, doubles and strings
isValid = true; 25 3.14 Four // Boolean // Integer // Double // String

PHP Language Basics


Constants, Data Types and Variables
Data types
Arrays $index=array('dell','sumsung','lg','a','b','c','d','e'); $multi=array('India'=>array('Delhi','Mumbai','Kol kata','Noida'), 'Pakistan'=>array('KArachi','lahOr','multan',' ), 'America'=>array('Newyork','Washington','l os angeles'));

PHP Language Basics


Constants, Data Types and Variables
Operators
Contains all of the operators like in C and Perl.

Statements
if, if/elseif Switch/case for, while, and do/while loops Include and require statements for code reuse

Built-in Functions
What comes In the box?
Directory Functions
Platform independent

Error Handling Functions


Recover from warnings and errors

Filesystem Functions
Access flat files Check directory, link, and file status information Copy, delete, and rename files

Built-in Functions
What comes In the box?
IMAP Functions
Manipulate mail boxes via the IMAP protocol

Mail Functions
mail($recipient, $subject, $message) Database Functions

Built-in Functions
What comes In the box?
Database Functions (cont.)
MySQL Oracle PostgreSQL SQL Server

MING
Macromedia Flash

PDF
Create/manipulate PDF files dynamically

Tricks and Tips


Coding
Prototype your web pages first
Separate the design of the site from the coding

Turn repetitive code into functions


Makes for more maintainable and reusable code

Turn grunt code into functions


Database access, configuration file access

Tricks and Tips


Debugging
Use scripts to dump form and session variables
Write scripts to dump data to discover bad or missing data

Tricks and Tips


Development Tools
Color coding editors
vim, Emacs, Visual SlickEdit

IDEs
Windows
Macromedia Dreamweaver Allaire Homesite Zends PHPEdit

PHP 5
Features
Complete objects
Objects with constructors Abstract classes Private, protected and abstract functions Private, protected and constant variables Namespaces Exception handling with try/catch blocks

Вам также может понравиться