www.northpolewebservice.com
www.northpolewebservice.com
“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)
Introduction to PHP
www.northpolewebservice.com
● 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
PHP History
www.northpolewebservice.com
Alternatives to PHP
● Practical extraction and Report Language (Perl)
● Active Server Pages (ASP)
● Java server pages (JSP)
● Ruby
www.northpolewebservice.com
How PHP generates
HTML/JS Web pages
2
Client
Browser
1 PHP
module
3
4
Apache
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
Hello World! (web oriented)
<html>
<head>
<title>My personal Hello World! PHP script</title>
</head>
<body>
<?
echo “Hello World!”;
?>
</html>
PHP tag, allow to insert PHP
code. Interpretation by PHP
module will substitute the code
with code output
www.northpolewebservice.com
Example of PHP :
 <!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP
script!";
?>
</body>
</html>
Output:
My first PHP script!
www.northpolewebservice.com
PHP 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
Example of echo statements:
 <!DOCTYPE html>
<html>
<body>
<?php
echo "<h2>PHP is
Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn
PHP!<br>";
echo "This ", "string ", "was
", "made ", "with multiple
parameters.";
?>
< >/body
</html>
 Output:
PHP is Fun!
Hello world!
I'm about to learn PHP!
This string was made with
multiple parameters.
www.northpolewebservice.com
Example of print statements:
 <!DOCTYPE html>
<html>
<body>
?php<
print "<h2>PHP is
Fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn
PHP!";
?>
</body>
< >/html
 Output:
PHP is Fun!
Hello world!
I'm about to learn PHP!
www.northpolewebservice.com
PHP Operators
Operators are used to operate on values. There are
four classifications of operators:
> Arithmetic
> Assignment
> Comparison
> Logical
www.northpolewebservice.com
PHP Operators
www.northpolewebservice.com
PHP Conditional Statements
•> if statement - use this statement to execute some code
only if a specified condition is true
•> if...else statement - use this statement to execute some
code if a condition is true and another code if the
condition is false
•> if...elseif....else statement - use this statement to select
one of several blocks of code to be executed
•> switch statement - use this statement to select one of
many blocks of code to be executed
www.northpolewebservice.com
•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
Arrays (I)
• Groups a set of variables, every element stored into an array as an
associated key (index to retrieve the element)
$books = array( 0=>”php manual”,1=>”perl manual”,2=>”C manual”);
$books = array( 0=>”php manual”,”perl manual”,”C manual”);
$books = array (“php manual”,”perl manual”,”C manual”);
echo $books[2]; output: C manual
• Arrays with PHP are associative
$books = array( “php manual”=>1,”perl manual”=>1,”C manual”=>1); // HASH
echo $books[“perl manual”]; output: 1
$books[“lisp manual”] = 1; // Add a new element
www.northpolewebservice.com
Arrays (II)
• Working on an arrays
$books = array( ”php manual”,”perl manual”,”C manual”);
• Common loop
for ($i=0; $i < count($books); $i++)
print ($i+1).”-st book of my library: $books[$i]”;
• each
$books = array( “php manual”=>1,”perl manual”=>2,”C manual”=>3);
while ($item = each( $books )) // Retrieve items one by one
print $item[“value”].”-st book of my library: ”.$item[“key”];
// 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
Arrays (III)
• Multidimensional arrays
$books = array( array(“title”=>“php manual”,”editor”=>”X”,”author”=>”A”),
array(“title”=>“perl manual”,”editor”=>”Y”,”author”=>”B”),
array(“title=>“C manual”,”editor”=>”Z”,author=>”C”));
• Common loop
for ($i=0; $i < count($books); $i++ )
print “$i-st book, title: ”.$books[$i][“title”].” author: “.$books[$i][“author”].
“ editor: “.$books[$i][“editor”];
// Add .”n” for text new page or “.<BR>” for HTML new page;
• Use list and each
for ($i=0; $i < count($books); $i++)
{
print “$i-st book is: “;
while ( list($key,$value) = each( $books[$i] ))
print “$key: $value ”;
print “<BR>”; // or “n”
}
www.northpolewebservice.com
Object Oriented PHP
• Encapsulation
• Polymorphism
• Inheritance
• Multiple Inheritance: actually unsupported
www.northpolewebservice.com
Encapsulation
<?
class dayOfWeek {
var $day,$month,$year;
function dayOfWeek($day,$month,$year)
{
$this->day = $day;
$this->month = $month;
$this->year = $year;
}
function calculate(){
if ($this->month==1){
$monthTmp=13;
$yearTmp = $this->year - 1;
}
if ($this->month == 2){
$monthTmp = 14;
$yearTmp = $this->year - 1;
}
$val4 = (($month+1)*3)/5;
$val5 = $year/4;
$val6 = $year/100;
$val7 = $year/400;
$val8 = $day+($month*2)+$val4+$val3+$val5-
$val6+$val7+2;
$val9 = $val8/7;
$val0 = $val8-($val9*7);
return $val0;
}
}
// Main
$instance =
new
dayOfWeek($_GET[“day”],$_GET[“week”],$
_GET[“ month”]);
print “You born on “.$instance->calculate().”n”;
?>
www.northpolewebservice.com
Inheritance
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
reuseMe::reuseMe();
}
function doTask4(){...}
function doTask5(){...}
function doTask6(){...}
}
www.northpolewebservice.com
Polymorphism
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
reuseMe::reuseMe();
}
function doTask4(){...}
function doTask5(){...}
function doTask6(){...}
function doTask3(){...}
}
www.northpolewebservice.com
Multiple 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
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@gmail.com
www.northpolewebservice.com

Ppt php

  • 1.
  • 2.
  • 3.
    “PHP is aserver-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) Introduction to PHP www.northpolewebservice.com
  • 4.
    ● 1994: Createdby 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 PHP History www.northpolewebservice.com
  • 5.
    Alternatives to PHP ●Practical extraction and Report Language (Perl) ● Active Server Pages (ASP) ● Java server pages (JSP) ● Ruby www.northpolewebservice.com
  • 6.
    How PHP generates HTML/JSWeb pages 2 Client Browser 1 PHP module 3 4 Apache 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
  • 7.
    Hello World! (weboriented) <html> <head> <title>My personal Hello World! PHP script</title> </head> <body> <? echo “Hello World!”; ?> </html> PHP tag, allow to insert PHP code. Interpretation by PHP module will substitute the code with code output www.northpolewebservice.com
  • 8.
    Example of PHP:  <!DOCTYPE html> <html> <body> <?php echo "My first PHP script!"; ?> </body> </html> Output: My first PHP script! www.northpolewebservice.com
  • 9.
    PHP echo andprint 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.
    Example of echostatements:  <!DOCTYPE html> <html> <body> <?php echo "<h2>PHP is Fun!</h2>"; echo "Hello world!<br>"; echo "I'm about to learn PHP!<br>"; echo "This ", "string ", "was ", "made ", "with multiple parameters."; ?> < >/body </html>  Output: PHP is Fun! Hello world! I'm about to learn PHP! This string was made with multiple parameters. www.northpolewebservice.com
  • 11.
    Example of printstatements:  <!DOCTYPE html> <html> <body> ?php< print "<h2>PHP is Fun!</h2>"; print "Hello world!<br>"; print "I'm about to learn PHP!"; ?> </body> < >/html  Output: PHP is Fun! Hello world! I'm about to learn PHP! www.northpolewebservice.com
  • 12.
    PHP Operators Operators areused to operate on values. There are four classifications of operators: > Arithmetic > Assignment > Comparison > Logical www.northpolewebservice.com
  • 13.
  • 14.
    PHP Conditional Statements •>if statement - use this statement to execute some code only if a specified condition is true •> if...else statement - use this statement to execute some code if a condition is true and another code if the condition is false •> if...elseif....else statement - use this statement to select one of several blocks of code to be executed •> switch statement - use this statement to select one of many blocks of code to be executed www.northpolewebservice.com
  • 15.
    •Use the if....elsestatement to execute some code if a condition is true and another code if a condition is false. www.northpolewebservice.com
  • 16.
    Arrays (I) • Groupsa set of variables, every element stored into an array as an associated key (index to retrieve the element) $books = array( 0=>”php manual”,1=>”perl manual”,2=>”C manual”); $books = array( 0=>”php manual”,”perl manual”,”C manual”); $books = array (“php manual”,”perl manual”,”C manual”); echo $books[2]; output: C manual • Arrays with PHP are associative $books = array( “php manual”=>1,”perl manual”=>1,”C manual”=>1); // HASH echo $books[“perl manual”]; output: 1 $books[“lisp manual”] = 1; // Add a new element www.northpolewebservice.com
  • 17.
    Arrays (II) • Workingon an arrays $books = array( ”php manual”,”perl manual”,”C manual”); • Common loop for ($i=0; $i < count($books); $i++) print ($i+1).”-st book of my library: $books[$i]”; • each $books = array( “php manual”=>1,”perl manual”=>2,”C manual”=>3); while ($item = each( $books )) // Retrieve items one by one print $item[“value”].”-st book of my library: ”.$item[“key”]; // 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
  • 18.
    Arrays (III) • Multidimensionalarrays $books = array( array(“title”=>“php manual”,”editor”=>”X”,”author”=>”A”), array(“title”=>“perl manual”,”editor”=>”Y”,”author”=>”B”), array(“title=>“C manual”,”editor”=>”Z”,author=>”C”)); • Common loop for ($i=0; $i < count($books); $i++ ) print “$i-st book, title: ”.$books[$i][“title”].” author: “.$books[$i][“author”]. “ editor: “.$books[$i][“editor”]; // Add .”n” for text new page or “.<BR>” for HTML new page; • Use list and each for ($i=0; $i < count($books); $i++) { print “$i-st book is: “; while ( list($key,$value) = each( $books[$i] )) print “$key: $value ”; print “<BR>”; // or “n” } www.northpolewebservice.com
  • 19.
    Object Oriented PHP •Encapsulation • Polymorphism • Inheritance • Multiple Inheritance: actually unsupported www.northpolewebservice.com
  • 20.
    Encapsulation <? class dayOfWeek { var$day,$month,$year; function dayOfWeek($day,$month,$year) { $this->day = $day; $this->month = $month; $this->year = $year; } function calculate(){ if ($this->month==1){ $monthTmp=13; $yearTmp = $this->year - 1; } if ($this->month == 2){ $monthTmp = 14; $yearTmp = $this->year - 1; } $val4 = (($month+1)*3)/5; $val5 = $year/4; $val6 = $year/100; $val7 = $year/400; $val8 = $day+($month*2)+$val4+$val3+$val5- $val6+$val7+2; $val9 = $val8/7; $val0 = $val8-($val9*7); return $val0; } } // Main $instance = new dayOfWeek($_GET[“day”],$_GET[“week”],$ _GET[“ month”]); print “You born on “.$instance->calculate().”n”; ?> www.northpolewebservice.com
  • 21.
    Inheritance Allow the creationof a hierarchy of classes Class reuseMe { function reuseMe(){...} function doTask1(){...} function doTask2(){...} function doTask3(){...} } Class extends reuseMe { function example(){ ... // local initializations // call super constructor reuseMe::reuseMe(); } function doTask4(){...} function doTask5(){...} function doTask6(){...} } www.northpolewebservice.com
  • 22.
    Polymorphism A member functioncan 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 reuseMe::reuseMe(); } function doTask4(){...} function doTask5(){...} function doTask6(){...} function doTask3(){...} } www.northpolewebservice.com
  • 23.
    Multiple Inheritance notactually 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
  • 24.
    Contact us:- Tofind 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:- [email protected] www.northpolewebservice.com