SlideShare a Scribd company logo
1 of 28
PHP Scripting language
Ludovico Antonio Muratori
Ci S.B.i.C. snc
Cesena, ITALY
PHP Stands for Hypertext Preprocessor
Agenda
1- Warm up revision about SQL & XAMPP 10 min
2- ppt teacher demonstrate about PHP 15m
3- Video about programing by PHP real life 5min
4- Practical work Students divided in groups and use
notepad / Atom , Dream weaver , any explorer to create
very simple dynamic web page 30 min
7- Questions and answers as pretest about PHP 5 min
8-Refelection 5 min
9- Home work 5 min
Warmp Up
Revision about SQL & XAMPP 10 min
Introduction 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)
PHP 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
Alternatives to PHP
● Practical extraction and Report Language (Perl)
● Active Server Pages (ASP)
● Java server pages (JSP)
● Ruby
(Good) Topics about PHP
● Open-source
● Easy to use ( C-like and Perl-like syntax)
● Stable and fast
● Multiplatform
● Many databases support
● Many common built-in libraries
● Pre-installed in Linux distributions
How 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
2
Client
Browser
1 PHP
module
3
4
Apache
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
Variables (I)
• To use or assign variable $ must be present before the name of the
variable
• The assign operator is '='
• There is no need to declare the type of the variable
• the current stored value produces an implicit type-casting of the
variable.
• A variable can be used before to be assigned
$A = 1;
$B = “2”;
$C = ($A + $B); // Integer sum
$D = $A . $B; // String concatenation
echo $C; // prints 3
echo $D;// prints 12
Variables (II)
• Function isset tests if a variable is assigned or not
$A = 1;
if (isset($A))
print “A isset”
if (!isset($B))
print “B is NOT set”;
• Using $$
$help = “hiddenVar”;
$$help = “hidden Value”;
echo $$help; // prints hidden Value
$$help = 10;
$help = $$help * $$help;
echo $help; // print 100
Strings (I)
• A string is a sequence of chars
$stringTest = “this is a sequence of chars”;
echo $stringTest[0]; output: t
echo $stringTest; output: this is a sequence of chars
• A single quoted strings is displayed “as-is”
$age = 37;
$stringTest = 'I am $age years old'; // output: I am $age years old
$stringTest = “I am $age years old”; // output: I am 37 years old
• Concatenation
$conc = ”is “.”a “.”composed “.”string”;
echo $conc; // output: is a composed string
$newConc = 'Also $conc '.$conc;
echo $newConc; // output: Also $conc is a composed string
Strings (II)
• Explode function
$sequence = “A,B,C,D,E,F,G”;
$elements = explode (“,”,$sequence);
// Now elements is an array with all substrings between “,”
char
echo $elemets[0]; // output: A;
echo $elemets[1]; // output: B;
echo $elemets[2]; // output: C;
echo $elemets[3]; // output: D;
echo $elemets[4]; // output: E;
echo $elemets[5]; // output: F;
echo $elemets[6]; // output: G;
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
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
Arrays (II)
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”
}
Case study (small database I)
• You need to build one or more web pages to manage your library, but:
– “You have no time or no knoledge on how to plan and design
database”
– or “You have no time or knolwdge on how to install a free
database”
– And “The database to implement is small” (about few
thousands entries, but depends on server configuration)
Case study (small database II)
#cat /usr/local/myDatabaseDirectory/library.txt
php manual X A 330
perl manual Y B 540
C manual Z C 480
(fields separated by tabs: 'php manual<tab>X<tab>A', new line at the end of each
entry)
<? // script to show all book in my library
$books = file(“/usr/local/myDatabaseDirectory/library.txt”); // retrieve library “database”
for ($i=0; $i<count($books), $i++ )
$books_array[$i] = explode( “t”, $books[$i]); // Extract elements from line
...
for ($i=0; $i<count($books_array), $i++ )
print “$i-st book, title: ”.$books_array[$i][“title”].” author: “.$books_array[$i][“author”].
“ editor: “.$books_array[$i][“editor”].”<BR>”;
Case study
A way to reuse code (I)
Using functions is possible to write more general code, to allow us to
reuse it to add feature:
– For the same project (always try to write reusable code, also you
will work for a short time on a project)
– For new projects
<? // config.php, is a good idea to use configuration files
$tableFiles = array ( “books”=>”/usr/local/myDatabaseDirectory/books.txt”);
$bookTableFields = array (“title”,”author”,”editor”,”pages”);
// future development of the library project (add new tables)
$tableFiles = array ( “users”=>”/usr/local/myDatabaseDirectory/users.txt”);
$userTableFields = array (“code”,“firstName”,”lastName”,”age”,”institute”);
?>
Case study
A way to reuse code (II)
<? // script to show all book in my library
$books = file(“/usr/local/myDatabaseDirectory/library.txt”);
// retrieve library “database”
for ($i=0; $i<count($books), $i++ )
$books_array[$i] = explode( “t”, $books[$i]); // Extract elements from line
...
for ($i=0; $i<count($books_array), $i++ )
print “$i-st book, title: ”.$books_array[$i][“title”].” author:
“.$books_array[$i][“author”].
“ editor: “.$books_array[$i][“editor”].”<BR>”;
Functions in details (I)
The syntax to implement a user-defined
function is :
function function_name([parameters-list]opt)
{……implementation code……}
parameters-list is a sequence of variables separated by “,”
• it’s not allowed to overload the name of an existing function;
• Function names aren’t case-sensitive;
• To each parameter can be assigned a default value;
• arguments can be passed by value or by reference
• It’s possible using a variable number of parameters
•
Object Oriented PHP
● Encapsulation
● Polymorphism
● Inheritance
● Multiple Inheritance: actually unsupported
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”;
?>
Allow the creation of a hierarchy of classes
Inheritance
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(){...}
}
Polymorphism
Class extends reuseMe {
function example(){
... // local initializations
// call super constructor
reuseMe::reuseMe();
}
function doTask4(){...}
function doTask5(){...}
function doTask6(){...}
function doTask3(){...}
}
class reuseMe {
function
reuseMe(){...}
function
doTask1(){...}
function
doTask2(){...}
function
doTask3(){...}
}
A member function can override superclass
implementation. Allow each subclass to
reimplement a common interfaces.
Multiple Inheritance not actually supported by
PHP
class extends reuseMe1,reuseMe2 {...}
class reuseMe1 {
function reuseMe1(){...}
function doTask1(){...}
function doTask2(){...}
function doTask3(){...}
}
class reuseMe2 {
function reuseMe2(){...}
function doTask3(){...}
function doTask4(){...}
function doTask5(){...}
}
Bibliography
[1] “PHP and MySQL Web Development”, Luke Welling and Laura
Thomson, SA

More Related Content

What's hot

Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Kris Wallsmith
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Kris Wallsmith
 
solving little problems
solving little problemssolving little problems
solving little problemsAustin Ziegler
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupKacper Gunia
 
Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Jacopo Romei
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101hendrikvb
 
An Introduction to Symfony
An Introduction to SymfonyAn Introduction to Symfony
An Introduction to Symfonyxopn
 
Symfony War Stories
Symfony War StoriesSymfony War Stories
Symfony War StoriesJakub Zalas
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackUAnshu Prateek
 
Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Jakub Zalas
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHPWim Godden
 

What's hot (20)

Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
Intro to PHP
Intro to PHPIntro to PHP
Intro to PHP
 
New in php 7
New in php 7New in php 7
New in php 7
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
solving little problems
solving little problemssolving little problems
solving little problems
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
My shell
My shellMy shell
My shell
 
Modern php
Modern phpModern php
Modern php
 
Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
An Introduction to Symfony
An Introduction to SymfonyAn Introduction to Symfony
An Introduction to Symfony
 
Symfony War Stories
Symfony War StoriesSymfony War Stories
Symfony War Stories
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 

Similar to Php introduction

Similar to Php introduction (20)

Ch1(introduction to php)
Ch1(introduction to php)Ch1(introduction to php)
Ch1(introduction to php)
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
 
Drupal 8: A story of growing up and getting off the island
Drupal 8: A story of growing up and getting off the islandDrupal 8: A story of growing up and getting off the island
Drupal 8: A story of growing up and getting off the island
 
2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphp
 
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
 
Phphacku iitd
Phphacku iitdPhphacku iitd
Phphacku iitd
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
PHP for hacks
PHP for hacksPHP for hacks
PHP for hacks
 
Sprockets
SprocketsSprockets
Sprockets
 
Prersentation
PrersentationPrersentation
Prersentation
 
Php hacku
Php hackuPhp hacku
Php hacku
 
Php with mysql ppt
Php with mysql pptPhp with mysql ppt
Php with mysql ppt
 
Lecture8
Lecture8Lecture8
Lecture8
 
CakePHP
CakePHPCakePHP
CakePHP
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Building an e:commerce site with PHP
Building an e:commerce site with PHPBuilding an e:commerce site with PHP
Building an e:commerce site with PHP
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 

More from Osama Ghandour Geris

functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...Osama Ghandour Geris
 
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.pptPython week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.pptOsama Ghandour Geris
 
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 10  2020 2021 covid 19 for g10 by eng.osama mansourPython cs.1.12 week 10  2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansourOsama Ghandour Geris
 
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
Python cs.1.12 week 9 10  2020-2021 covid 19 for g10 by eng.osama ghandourPython cs.1.12 week 9 10  2020-2021 covid 19 for g10 by eng.osama ghandour
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandourOsama Ghandour Geris
 
Python week 7 8 2019-2020 for grade 10
Python week 7 8 2019-2020 for grade 10Python week 7 8 2019-2020 for grade 10
Python week 7 8 2019-2020 for grade 10Osama Ghandour Geris
 
Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10 Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10 Osama Ghandour Geris
 
Python week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandourPython week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandourOsama Ghandour Geris
 
Python week 4 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandourPython week 4 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandourOsama Ghandour Geris
 
Programming intro variables constants - arithmetic and assignment operators
Programming intro variables   constants - arithmetic and assignment operatorsProgramming intro variables   constants - arithmetic and assignment operators
Programming intro variables constants - arithmetic and assignment operatorsOsama Ghandour Geris
 
Mobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osamaMobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osamaOsama Ghandour Geris
 
Css week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandourCss week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandourOsama Ghandour Geris
 
How to print a sketch up drawing in 3d
How to print a sketch up drawing  in 3dHow to print a sketch up drawing  in 3d
How to print a sketch up drawing in 3dOsama Ghandour Geris
 
7 types of presentation styles on line
7 types of presentation styles on line7 types of presentation styles on line
7 types of presentation styles on lineOsama Ghandour Geris
 
Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020Osama Ghandour Geris
 

More from Osama Ghandour Geris (20)

functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
 
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.pptPython week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
 
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 10  2020 2021 covid 19 for g10 by eng.osama mansourPython cs.1.12 week 10  2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
 
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
Python cs.1.12 week 9 10  2020-2021 covid 19 for g10 by eng.osama ghandourPython cs.1.12 week 9 10  2020-2021 covid 19 for g10 by eng.osama ghandour
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
 
Python week 7 8 2019-2020 for grade 10
Python week 7 8 2019-2020 for grade 10Python week 7 8 2019-2020 for grade 10
Python week 7 8 2019-2020 for grade 10
 
Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10 Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10
 
Python week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandourPython week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandour
 
Python week 4 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandourPython week 4 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandour
 
Programming intro variables constants - arithmetic and assignment operators
Programming intro variables   constants - arithmetic and assignment operatorsProgramming intro variables   constants - arithmetic and assignment operators
Programming intro variables constants - arithmetic and assignment operators
 
Mobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osamaMobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osama
 
Python week 1 2020-2021
Python week 1 2020-2021Python week 1 2020-2021
Python week 1 2020-2021
 
6 css week12 2020 2021 for g10
6 css week12 2020 2021 for g106 css week12 2020 2021 for g10
6 css week12 2020 2021 for g10
 
Css week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandourCss week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandour
 
Cooding history
Cooding history Cooding history
Cooding history
 
Computer networks--network
Computer networks--networkComputer networks--network
Computer networks--network
 
How to print a sketch up drawing in 3d
How to print a sketch up drawing  in 3dHow to print a sketch up drawing  in 3d
How to print a sketch up drawing in 3d
 
Google sketch up-tutorial
Google sketch up-tutorialGoogle sketch up-tutorial
Google sketch up-tutorial
 
7 types of presentation styles on line
7 types of presentation styles on line7 types of presentation styles on line
7 types of presentation styles on line
 
Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020
 
How to use common app
How to use common appHow to use common app
How to use common app
 

Recently uploaded

Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 

Recently uploaded (20)

FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 

Php introduction

  • 1. PHP Scripting language Ludovico Antonio Muratori Ci S.B.i.C. snc Cesena, ITALY PHP Stands for Hypertext Preprocessor
  • 2.
  • 3. Agenda 1- Warm up revision about SQL & XAMPP 10 min 2- ppt teacher demonstrate about PHP 15m 3- Video about programing by PHP real life 5min 4- Practical work Students divided in groups and use notepad / Atom , Dream weaver , any explorer to create very simple dynamic web page 30 min 7- Questions and answers as pretest about PHP 5 min 8-Refelection 5 min 9- Home work 5 min
  • 4. Warmp Up Revision about SQL & XAMPP 10 min
  • 5. Introduction 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)
  • 6. PHP 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
  • 7. Alternatives to PHP ● Practical extraction and Report Language (Perl) ● Active Server Pages (ASP) ● Java server pages (JSP) ● Ruby
  • 8. (Good) Topics about PHP ● Open-source ● Easy to use ( C-like and Perl-like syntax) ● Stable and fast ● Multiplatform ● Many databases support ● Many common built-in libraries ● Pre-installed in Linux distributions
  • 9. How 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 2 Client Browser 1 PHP module 3 4 Apache
  • 10. 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
  • 11. Variables (I) • To use or assign variable $ must be present before the name of the variable • The assign operator is '=' • There is no need to declare the type of the variable • the current stored value produces an implicit type-casting of the variable. • A variable can be used before to be assigned $A = 1; $B = “2”; $C = ($A + $B); // Integer sum $D = $A . $B; // String concatenation echo $C; // prints 3 echo $D;// prints 12
  • 12. Variables (II) • Function isset tests if a variable is assigned or not $A = 1; if (isset($A)) print “A isset” if (!isset($B)) print “B is NOT set”; • Using $$ $help = “hiddenVar”; $$help = “hidden Value”; echo $$help; // prints hidden Value $$help = 10; $help = $$help * $$help; echo $help; // print 100
  • 13. Strings (I) • A string is a sequence of chars $stringTest = “this is a sequence of chars”; echo $stringTest[0]; output: t echo $stringTest; output: this is a sequence of chars • A single quoted strings is displayed “as-is” $age = 37; $stringTest = 'I am $age years old'; // output: I am $age years old $stringTest = “I am $age years old”; // output: I am 37 years old • Concatenation $conc = ”is “.”a “.”composed “.”string”; echo $conc; // output: is a composed string $newConc = 'Also $conc '.$conc; echo $newConc; // output: Also $conc is a composed string
  • 14. Strings (II) • Explode function $sequence = “A,B,C,D,E,F,G”; $elements = explode (“,”,$sequence); // Now elements is an array with all substrings between “,” char echo $elemets[0]; // output: A; echo $elemets[1]; // output: B; echo $elemets[2]; // output: C; echo $elemets[3]; // output: D; echo $elemets[4]; // output: E; echo $elemets[5]; // output: F; echo $elemets[6]; // output: G;
  • 15. 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
  • 16. 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 Arrays (II)
  • 17. 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” }
  • 18. Case study (small database I) • You need to build one or more web pages to manage your library, but: – “You have no time or no knoledge on how to plan and design database” – or “You have no time or knolwdge on how to install a free database” – And “The database to implement is small” (about few thousands entries, but depends on server configuration)
  • 19. Case study (small database II) #cat /usr/local/myDatabaseDirectory/library.txt php manual X A 330 perl manual Y B 540 C manual Z C 480 (fields separated by tabs: 'php manual<tab>X<tab>A', new line at the end of each entry) <? // script to show all book in my library $books = file(“/usr/local/myDatabaseDirectory/library.txt”); // retrieve library “database” for ($i=0; $i<count($books), $i++ ) $books_array[$i] = explode( “t”, $books[$i]); // Extract elements from line ... for ($i=0; $i<count($books_array), $i++ ) print “$i-st book, title: ”.$books_array[$i][“title”].” author: “.$books_array[$i][“author”]. “ editor: “.$books_array[$i][“editor”].”<BR>”;
  • 20. Case study A way to reuse code (I) Using functions is possible to write more general code, to allow us to reuse it to add feature: – For the same project (always try to write reusable code, also you will work for a short time on a project) – For new projects <? // config.php, is a good idea to use configuration files $tableFiles = array ( “books”=>”/usr/local/myDatabaseDirectory/books.txt”); $bookTableFields = array (“title”,”author”,”editor”,”pages”); // future development of the library project (add new tables) $tableFiles = array ( “users”=>”/usr/local/myDatabaseDirectory/users.txt”); $userTableFields = array (“code”,“firstName”,”lastName”,”age”,”institute”); ?>
  • 21. Case study A way to reuse code (II) <? // script to show all book in my library $books = file(“/usr/local/myDatabaseDirectory/library.txt”); // retrieve library “database” for ($i=0; $i<count($books), $i++ ) $books_array[$i] = explode( “t”, $books[$i]); // Extract elements from line ... for ($i=0; $i<count($books_array), $i++ ) print “$i-st book, title: ”.$books_array[$i][“title”].” author: “.$books_array[$i][“author”]. “ editor: “.$books_array[$i][“editor”].”<BR>”;
  • 22. Functions in details (I) The syntax to implement a user-defined function is : function function_name([parameters-list]opt) {……implementation code……} parameters-list is a sequence of variables separated by “,” • it’s not allowed to overload the name of an existing function; • Function names aren’t case-sensitive; • To each parameter can be assigned a default value; • arguments can be passed by value or by reference • It’s possible using a variable number of parameters •
  • 23. Object Oriented PHP ● Encapsulation ● Polymorphism ● Inheritance ● Multiple Inheritance: actually unsupported
  • 24. 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”; ?>
  • 25. Allow the creation of a hierarchy of classes Inheritance 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(){...} }
  • 26. Polymorphism Class extends reuseMe { function example(){ ... // local initializations // call super constructor reuseMe::reuseMe(); } function doTask4(){...} function doTask5(){...} function doTask6(){...} function doTask3(){...} } class reuseMe { function reuseMe(){...} function doTask1(){...} function doTask2(){...} function doTask3(){...} } A member function can override superclass implementation. Allow each subclass to reimplement a common interfaces.
  • 27. Multiple Inheritance not actually supported by PHP class extends reuseMe1,reuseMe2 {...} class reuseMe1 { function reuseMe1(){...} function doTask1(){...} function doTask2(){...} function doTask3(){...} } class reuseMe2 { function reuseMe2(){...} function doTask3(){...} function doTask4(){...} function doTask5(){...} }
  • 28. Bibliography [1] “PHP and MySQL Web Development”, Luke Welling and Laura Thomson, SA