SlideShare a Scribd company logo
PHP Scripting language
Vibrant Technology & Computers
Vashi,Navi Mumbai
www.vibranttechnologies.co.in
Php course-in-navimumbai
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
module3
4
Apache
Working of PHP
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
Thank you….
Ad

Recommended

Php introduction
Php introduction
Osama Ghandour Geris
Ā 
Looping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
Mark Baker
Ā 
Building Lithium Apps
Building Lithium Apps
Nate Abele
Ā 
Drupal Field API. Practical usage
Drupal Field API. Practical usage
Pavel Makhrinsky
Ā 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHP
BUDNET
Ā 
SPL: The Missing Link in Development
SPL: The Missing Link in Development
jsmith92
Ā 
Sorting arrays in PHP
Sorting arrays in PHP
Vineet Kumar Saini
Ā 
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Nate Abele
Ā 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP Extension
Adam Trachtenberg
Ā 
The State of Lithium
The State of Lithium
Nate Abele
Ā 
The Origin of Lithium
The Origin of Lithium
Nate Abele
Ā 
PHP 良儽實踐 (Best Practice)
PHP 良儽實踐 (Best Practice)
Win Yu
Ā 
Drupal 8 migrate!
Drupal 8 migrate!
Pavel Makhrinsky
Ā 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
Michelangelo van Dam
Ā 
PHP 5.3 Overview
PHP 5.3 Overview
jsmith92
Ā 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3
Matthew Turland
Ā 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
Hugo Hamon
Ā 
Lithium Best
Lithium Best
Richard McIntyre
Ā 
rtwerewr
rtwerewr
esolinhighered
Ā 
The Zen of Lithium
The Zen of Lithium
Nate Abele
Ā 
Data Types In PHP
Data Types In PHP
Mark Niebergall
Ā 
Php Tutorials for Beginners
Php Tutorials for Beginners
Vineet Kumar Saini
Ā 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
Nate Abele
Ā 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
Patrick Allaert
Ā 
PHP Language Trivia
PHP Language Trivia
Nikita Popov
Ā 
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Hugo Hamon
Ā 
Multilingual drupal 7
Multilingual drupal 7
Pavel Makhrinsky
Ā 
The History of PHPersistence
The History of PHPersistence
Hugo Hamon
Ā 
R.K.Lilley - Up in air trilogy ( 2nd book "Mile High" )
R.K.Lilley - Up in air trilogy ( 2nd book "Mile High" )
Dijana Veglia
Ā 
R. k. lilley up in the air 03 - grounded
R. k. lilley up in the air 03 - grounded
Aricia Aguiar
Ā 

More Related Content

What's hot (20)

Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP Extension
Adam Trachtenberg
Ā 
The State of Lithium
The State of Lithium
Nate Abele
Ā 
The Origin of Lithium
The Origin of Lithium
Nate Abele
Ā 
PHP 良儽實踐 (Best Practice)
PHP 良儽實踐 (Best Practice)
Win Yu
Ā 
Drupal 8 migrate!
Drupal 8 migrate!
Pavel Makhrinsky
Ā 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
Michelangelo van Dam
Ā 
PHP 5.3 Overview
PHP 5.3 Overview
jsmith92
Ā 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3
Matthew Turland
Ā 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
Hugo Hamon
Ā 
Lithium Best
Lithium Best
Richard McIntyre
Ā 
rtwerewr
rtwerewr
esolinhighered
Ā 
The Zen of Lithium
The Zen of Lithium
Nate Abele
Ā 
Data Types In PHP
Data Types In PHP
Mark Niebergall
Ā 
Php Tutorials for Beginners
Php Tutorials for Beginners
Vineet Kumar Saini
Ā 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
Nate Abele
Ā 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
Patrick Allaert
Ā 
PHP Language Trivia
PHP Language Trivia
Nikita Popov
Ā 
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Hugo Hamon
Ā 
Multilingual drupal 7
Multilingual drupal 7
Pavel Makhrinsky
Ā 
The History of PHPersistence
The History of PHPersistence
Hugo Hamon
Ā 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP Extension
Adam Trachtenberg
Ā 
The State of Lithium
The State of Lithium
Nate Abele
Ā 
The Origin of Lithium
The Origin of Lithium
Nate Abele
Ā 
PHP 良儽實踐 (Best Practice)
PHP 良儽實踐 (Best Practice)
Win Yu
Ā 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
Michelangelo van Dam
Ā 
PHP 5.3 Overview
PHP 5.3 Overview
jsmith92
Ā 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3
Matthew Turland
Ā 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
Hugo Hamon
Ā 
The Zen of Lithium
The Zen of Lithium
Nate Abele
Ā 
Php Tutorials for Beginners
Php Tutorials for Beginners
Vineet Kumar Saini
Ā 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
Nate Abele
Ā 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
Patrick Allaert
Ā 
PHP Language Trivia
PHP Language Trivia
Nikita Popov
Ā 
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Hugo Hamon
Ā 
Multilingual drupal 7
Multilingual drupal 7
Pavel Makhrinsky
Ā 
The History of PHPersistence
The History of PHPersistence
Hugo Hamon
Ā 

Viewers also liked (11)

R.K.Lilley - Up in air trilogy ( 2nd book "Mile High" )
R.K.Lilley - Up in air trilogy ( 2nd book "Mile High" )
Dijana Veglia
Ā 
R. k. lilley up in the air 03 - grounded
R. k. lilley up in the air 03 - grounded
Aricia Aguiar
Ā 
R.K.Lilley - Up in air trilogy ( 3rd book "Grounded )
R.K.Lilley - Up in air trilogy ( 3rd book "Grounded )
Dijana Veglia
Ā 
تطوير المناهج وأسس ŲŖŁ†ŲøŁŠŁ…Ł‡Ų§8
تطوير المناهج وأسس ŲŖŁ†ŲøŁŠŁ…Ł‡Ų§8
Magdy Aly
Ā 
المحاضرة Ų§Ł„Ų£ŁˆŁ„Ł‰ Ų£Ų³Ų³ المناهج
المحاضرة Ų§Ł„Ų£ŁˆŁ„Ł‰ Ų£Ų³Ų³ المناهج
asmart1987
Ā 
اتجاهات Ł…Ų¹Ų§ŲµŲ±Ų© في تطوير المناهج
اتجاهات Ł…Ų¹Ų§ŲµŲ±Ų© في تطوير المناهج
Heba Hoba
Ā 
علم المناهج Ų§Ł„ŲÆŲ±Ų§Ų³ŁŠŲ© 6 Ł†ŲøŲ±ŁŠŲ§ŲŖ المنهج
علم المناهج Ų§Ł„ŲÆŲ±Ų§Ų³ŁŠŲ© 6 Ł†ŲøŲ±ŁŠŲ§ŲŖ المنهج
yusriya aljamil
Ā 
مهارات Ų§Ł„Ł…Ų°Ų§ŁƒŲ±Ų© الناجحة ŁˆŲÆŲ®ŁˆŁ„ الامتحان
مهارات Ų§Ł„Ł…Ų°Ų§ŁƒŲ±Ų© الناجحة ŁˆŲÆŲ®ŁˆŁ„ الامتحان
عبدالله باخريصة
Ā 
Ų¹Ų±Ų¶ ŲØŁˆŲ±ŲØŁˆŁŠŁ†ŲŖ دورة كيف تدير ذاتك ŁˆŲŖŁ‚ŁˆŲÆ رحلة حياتك
Ų¹Ų±Ų¶ ŲØŁˆŲ±ŲØŁˆŁŠŁ†ŲŖ دورة كيف تدير ذاتك ŁˆŲŖŁ‚ŁˆŲÆ رحلة حياتك
Ahmed Rezq
Ā 
كتابة مقترح Ł…Ų“Ų±ŁˆŲ¹
كتابة مقترح Ł…Ų“Ų±ŁˆŲ¹
Mohammad Abu Alkomboz
Ā 
كيف تكتب Ų®Ų·Ų© ŲŖŲ“ŲŗŁŠŁ„ŁŠŲ© لمنظمة - ŲÆ. طارق Ų§Ł„Ų³ŁˆŁŠŲÆŲ§Ł†
كيف تكتب Ų®Ų·Ų© ŲŖŲ“ŲŗŁŠŁ„ŁŠŲ© لمنظمة - ŲÆ. طارق Ų§Ł„Ų³ŁˆŁŠŲÆŲ§Ł†
Mohammed Azab
Ā 
R.K.Lilley - Up in air trilogy ( 2nd book "Mile High" )
R.K.Lilley - Up in air trilogy ( 2nd book "Mile High" )
Dijana Veglia
Ā 
R. k. lilley up in the air 03 - grounded
R. k. lilley up in the air 03 - grounded
Aricia Aguiar
Ā 
R.K.Lilley - Up in air trilogy ( 3rd book "Grounded )
R.K.Lilley - Up in air trilogy ( 3rd book "Grounded )
Dijana Veglia
Ā 
تطوير المناهج وأسس ŲŖŁ†ŲøŁŠŁ…Ł‡Ų§8
تطوير المناهج وأسس ŲŖŁ†ŲøŁŠŁ…Ł‡Ų§8
Magdy Aly
Ā 
المحاضرة Ų§Ł„Ų£ŁˆŁ„Ł‰ Ų£Ų³Ų³ المناهج
المحاضرة Ų§Ł„Ų£ŁˆŁ„Ł‰ Ų£Ų³Ų³ المناهج
asmart1987
Ā 
اتجاهات Ł…Ų¹Ų§ŲµŲ±Ų© في تطوير المناهج
اتجاهات Ł…Ų¹Ų§ŲµŲ±Ų© في تطوير المناهج
Heba Hoba
Ā 
علم المناهج Ų§Ł„ŲÆŲ±Ų§Ų³ŁŠŲ© 6 Ł†ŲøŲ±ŁŠŲ§ŲŖ المنهج
علم المناهج Ų§Ł„ŲÆŲ±Ų§Ų³ŁŠŲ© 6 Ł†ŲøŲ±ŁŠŲ§ŲŖ المنهج
yusriya aljamil
Ā 
مهارات Ų§Ł„Ł…Ų°Ų§ŁƒŲ±Ų© الناجحة ŁˆŲÆŲ®ŁˆŁ„ الامتحان
مهارات Ų§Ł„Ł…Ų°Ų§ŁƒŲ±Ų© الناجحة ŁˆŲÆŲ®ŁˆŁ„ الامتحان
عبدالله باخريصة
Ā 
Ų¹Ų±Ų¶ ŲØŁˆŲ±ŲØŁˆŁŠŁ†ŲŖ دورة كيف تدير ذاتك ŁˆŲŖŁ‚ŁˆŲÆ رحلة حياتك
Ų¹Ų±Ų¶ ŲØŁˆŲ±ŲØŁˆŁŠŁ†ŲŖ دورة كيف تدير ذاتك ŁˆŲŖŁ‚ŁˆŲÆ رحلة حياتك
Ahmed Rezq
Ā 
كتابة مقترح Ł…Ų“Ų±ŁˆŲ¹
كتابة مقترح Ł…Ų“Ų±ŁˆŲ¹
Mohammad Abu Alkomboz
Ā 
كيف تكتب Ų®Ų·Ų© ŲŖŲ“ŲŗŁŠŁ„ŁŠŲ© لمنظمة - ŲÆ. طارق Ų§Ł„Ų³ŁˆŁŠŲÆŲ§Ł†
كيف تكتب Ų®Ų·Ų© ŲŖŲ“ŲŗŁŠŁ„ŁŠŲ© لمنظمة - ŲÆ. طارق Ų§Ł„Ų³ŁˆŁŠŲÆŲ§Ł†
Mohammed Azab
Ā 
Ad

Similar to Php course-in-navimumbai (20)

PHP Workshop Notes
PHP Workshop Notes
Pamela Fox
Ā 
Ch1(introduction to php)
Ch1(introduction to php)
Chhom Karath
Ā 
Introduction to PHP_ Lexical structure_Array_Function_String
Introduction to PHP_ Lexical structure_Array_Function_String
DeepakUlape2
Ā 
unit 1.pptx
unit 1.pptx
adityathote3
Ā 
Building an e:commerce site with PHP
Building an e:commerce site with PHP
webhostingguy
Ā 
Php classes in mumbai
Php classes in mumbai
Vibrant Technologies & Computers
Ā 
PHP - Introduction to PHP
PHP - Introduction to PHP
Vibrant Technologies & Computers
Ā 
PHP and MySQL with snapshots
PHP and MySQL with snapshots
richambra
Ā 
Phpwebdevelping
Phpwebdevelping
mohamed ashraf
Ā 
Unit 4-6 sem 7 Web Technologies.pptx
Unit 4-6 sem 7 Web Technologies.pptx
prathameshp9922
Ā 
Synapse india complain sharing info about php chaptr 26
Synapse india complain sharing info about php chaptr 26
SynapseindiaComplaints
Ā 
Training on php by cyber security infotech (csi)
Training on php by cyber security infotech (csi)
Cyber Security Infotech Pvt. Ltd.
Ā 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
Michelangelo van Dam
Ā 
Quick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHP
Sanju Sony Kurian
Ā 
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
kamalsmail1
Ā 
05php
05php
Shahid Usman
Ā 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
Ā 
Synapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on php
SynapseindiaComplaints
Ā 
Synapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on php
SynapseindiaComplaints
Ā 
PHP Scripting
PHP Scripting
Reem Alattas
Ā 
PHP Workshop Notes
PHP Workshop Notes
Pamela Fox
Ā 
Ch1(introduction to php)
Ch1(introduction to php)
Chhom Karath
Ā 
Introduction to PHP_ Lexical structure_Array_Function_String
Introduction to PHP_ Lexical structure_Array_Function_String
DeepakUlape2
Ā 
Building an e:commerce site with PHP
Building an e:commerce site with PHP
webhostingguy
Ā 
PHP and MySQL with snapshots
PHP and MySQL with snapshots
richambra
Ā 
Unit 4-6 sem 7 Web Technologies.pptx
Unit 4-6 sem 7 Web Technologies.pptx
prathameshp9922
Ā 
Synapse india complain sharing info about php chaptr 26
Synapse india complain sharing info about php chaptr 26
SynapseindiaComplaints
Ā 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
Michelangelo van Dam
Ā 
Quick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHP
Sanju Sony Kurian
Ā 
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
kamalsmail1
Ā 
Synapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on php
SynapseindiaComplaints
Ā 
Synapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on php
SynapseindiaComplaints
Ā 
PHP Scripting
PHP Scripting
Reem Alattas
Ā 
Ad

Recently uploaded (20)

Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
Ā 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
Ā 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
Ā 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
Ā 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
Ā 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
Ā 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
Ā 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
Ā 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
Ā 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
Ā 
ā€œMPU+: A Transformative Solution for Next-Gen AI at the Edge,ā€ a Presentation...
ā€œMPU+: A Transformative Solution for Next-Gen AI at the Edge,ā€ a Presentation...
Edge AI and Vision Alliance
Ā 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
Ā 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
Ā 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
Ā 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
Ā 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
Ā 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
Ā 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
Ā 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
Ā 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
Ā 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
Ā 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
Ā 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
Ā 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
Ā 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
Ā 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
Ā 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
Ā 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
Ā 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
Ā 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
Ā 
ā€œMPU+: A Transformative Solution for Next-Gen AI at the Edge,ā€ a Presentation...
ā€œMPU+: A Transformative Solution for Next-Gen AI at the Edge,ā€ a Presentation...
Edge AI and Vision Alliance
Ā 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
Ā 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
Ā 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
Ā 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
Ā 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
Ā 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
Ā 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
Ā 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
Ā 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
Ā 

Php course-in-navimumbai

  • 1. PHP Scripting language Vibrant Technology & Computers Vashi,Navi Mumbai www.vibranttechnologies.co.in
  • 3. 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)
  • 4. 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
  • 5. Alternatives to PHP ā— Practical extraction and Report Language (Perl) ā— Active Server Pages (ASP) ā— Java server pages (JSP) ā— Ruby
  • 6. (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
  • 7. 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 module3 4 Apache
  • 9. 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
  • 10. 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
  • 11. 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
  • 12. 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
  • 13. 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;
  • 14. 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
  • 15. • 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)
  • 16. 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ā€ }
  • 17. 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)
  • 18. 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>ā€;
  • 19. 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ā€); ?>
  • 20. 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>ā€;
  • 21. 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. 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ā€; ?>
  • 24. 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(){...} }
  • 25. 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.
  • 26. 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(){...} }
  • 27. Bibliography [1] ā€œPHP and MySQL Web Developmentā€, Luke Welling and Laura Thomson, SA