Title: Northpole01
1www.northpolewebservice.com
2Yikes
www.northpolewebservice.com
3Introduction to PHP
PHP is a server-side scripting language designed
specifically for the Web. Within an HTML page,
you can embed PHP code that will be executed each
time the page is visited. Your PHP code is
interpreted at the Web server and generates HTML
or other output that the visitor will see (PHP
and MySQL Web Development, Luke Welling and
Laura Thomson, SAMS)
www.northpolewebservice.com
4PHP History
- 1994 Created by Rasmis Lesdorf, software
engineer (part of Apache Team) - 1995 Called Personal Home Page Tool, then
released as version 2 with name PHP/FI (Form
Interpreter, to analyze SQL queries) - Half 1997 used by 50,000 web sites
- October 1998 used by 100,000 websites
- End 1999 used by 1,000,000 websites
www.northpolewebservice.com
5Alternatives to PHP
- Practical extraction and Report Language (Perl)
- Active Server Pages (ASP)
- Java server pages (JSP)
- Ruby
www.northpolewebservice.com
6How PHP generates HTML/JS Web pages
1 Client from browser send HTTP request (with
POST/GET variables) 2 Apache recognizes that a
PHP script is requested and sends the request to
PHP module 3 PHP interpreter executes PHP
script, collects script output and sends it
back 4 Apache replies to client using the PHP
script output as HTML output
www.northpolewebservice.com
7Hello World! (web oriented)
lthtmlgt ltheadgt lttitlegtMy personal Hello World!
PHP scriptlt/titlegt lt/headgt ltbodygt lt? echo Hello
World! ?gt lt/htmlgt
PHP tag, allow to insert PHP code. Interpretation
by PHP module will substitute the code with code
output
www.northpolewebservice.com
8www.northpolewebservice.com
9PHP echo and print statements-
- echo and print are more or less the same. They
are both used to output data to the screen. - The differences are small echo has no return
value while print has a return value of 1 so it
can be used in expressions. echo can take
multiple parameters (although such usage is rare)
while print can take one argument. echo is
marginally faster than print.
www.northpolewebservice.com
10 www.northpolewebservice.com
11www.northpolewebservice.com
12PHP Operators
Operators are used to operate on values. There
are four classifications of operators gt
Arithmetic gt Assignment gt Comparison
gt Logical
www.northpolewebservice.com
13PHP Operators
www.northpolewebservice.com
14PHP Conditional Statements
- gt if statement - use this statement to execute
some code only if a specified condition is true - gt if...else statement - use this statement to
execute some code if a condition is true and
another code if the condition is false - gt if...elseif....else statement - use this
statement to select one of several blocks of code
to be executed - gt switch statement - use this statement to select
one of many blocks of code to be executed
www.northpolewebservice.com
15- Use the if....else statement to execute some code
if a condition is true and another code if a
condition is false.
www.northpolewebservice.com
16Arrays (I)
- Groups a set of variables, every element stored
into an array as an associated key (index to
retrieve the element) - books array( 0gtphp manual,1gtperl
manual,2gtC manual) - books array( 0gtphp manual,perl manual,C
manual) - books array (php manual,perl manual,C
manual) - echo books2 output C manual
- Arrays with PHP are associative
- books array( php manualgt1,perl
manualgt1,C manualgt1) // HASH - echo booksperl manual output 1
- bookslisp manual 1 // Add a new element
www.northpolewebservice.com
17Arrays (II)
- Working on an arrays
- books array( php manual,perl manual,C
manual) - Common loop
- for (i0 i lt count(books) i)
- print (i1).-st book of my library
booksi - each
- books array( php manualgt1,perl
manualgt2,C manualgt3) - while (item each( books )) // Retrieve items
one by one - print itemvalue.-st book of my library
.itemkey - // each retrieve an array of two elements with
key and value of current element - each and list
- while ( list(value,key) each( books ))
- print value-st book of my library key
- // list collect the two element retrieved by
each and store them in two different // variables
www.northpolewebservice.com
18Arrays (III)
- Multidimensional arrays
- books array( array(titlegtphp
manual,editorgtX,authorgtA), - array(titlegtperl manual,editorgtY,
authorgtB), - array(titlegtC manual,editorgtZ,autho
rgtC)) - Common loop
- for (i0 i lt count(books) i )
- print i-st book, title .booksititle
. author .booksiauthor. - editor .booksieditor
- // Add .\n for text new page or .ltBRgt for
HTML new page - Use list and each
- for (i0 i lt count(books) i)
-
- print i-st book is
- while ( list(key,value) each( booksi
)) - print key value
- print ltBRgt // or \n
-
www.northpolewebservice.com
19Object Oriented PHP
- Encapsulation
- Polymorphism
- Inheritance
- Multiple Inheritance actually unsupported
www.northpolewebservice.com
20Encapsulation
val4 ((month1)3)/5 val5
year/4 val6 year/100 val7
year/400 val8 day(month2)val4val3
val5-val6val72 val9 val8/7 val0
val8-(val97) return val0 //
Main instance new dayOfWeek(_GETday,_
GETweek,_GET month) print You
born on .instance-gtcalculate().\n ?gt
lt? class dayOfWeek var day,month,year
function dayOfWeek(day,month,year)
this-gtday day this-gtmonth month
this-gtyear year function
calculate() if (this-gtmonth1)
monthTmp13 yearTmp this-gtyear - 1
if (this-gtmonth 2) monthTmp
14 yearTmp this-gtyear - 1
www.northpolewebservice.com
21Inheritance
Allow the creation of a hierarchy of classes
Class reuseMe function reuseMe()...
function doTask1()... function
doTask2()... function doTask3()...
Class extends reuseMe function example()
... // local initializations // call
super constructor reuseMereuseMe()
function doTask4()... function
doTask5()... function doTask6()...
www.northpolewebservice.com
22Polymorphism
A member function can override superclass
implementation. Allow each subclass to
reimplement a common interfaces.
class reuseMe function reuseMe()...
function doTask1()... function
doTask2()... function doTask3()...
Class extends reuseMe function example()
... // local initializations // call
super constructor reuseMereuseMe()
function doTask4()... function
doTask5()... function doTask6()...
function doTask3()...
www.northpolewebservice.com
23Multiple Inheritance not actually supported by
PHP
class reuseMe1 function reuseMe1()...
function doTask1()... function
doTask2()... function doTask3()...
class reuseMe2 function reuseMe2()...
function doTask3()... function
doTask4()... function doTask5()...
class extends reuseMe1,reuseMe2 ...
www.northpolewebservice.com
24THANK YOU
Contact us- To find out more or how we can help
you better
Address- C-127 ,2nd Floor, Ozi gym Building ,
Phase 8, Industrial Area, Mohali, 160055
Phone no- (91) 8872155107, 9779127768,
8360890672
Email- npolewebservice_at_gmail.com
www.northpolewebservice.com