SlideShare a Scribd company logo
PHP Scripting language
Vibrant Technology & Computers
Vashi,Navi Mumbai
www.vibranttechnologies.co.in
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….

More Related Content

What's hot

Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionAdam Trachtenberg
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of Lithium
Nate Abele
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of Lithium
Nate Abele
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)
Win Yu
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
Pavel Makhrinsky
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
Michelangelo van Dam
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New 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 PimpleDesign 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 LithiumThe Zen of Lithium
The Zen of Lithium
Nate Abele
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
Mark Niebergall
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp 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 FrameworksLithium: 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, ItalyPHP 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 TriviaPHP Language Trivia
PHP Language Trivia
Nikita Popov
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2Hugo Hamon
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
Hugo Hamon
 

What's hot (20)

Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP Extension
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of Lithium
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of Lithium
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
Lithium Best
Lithium Best Lithium Best
Lithium Best
 
rtwerewr
rtwerewrrtwerewr
rtwerewr
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 
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, ItalyPHP 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
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language Trivia
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
Multilingual drupal 7
Multilingual drupal 7Multilingual drupal 7
Multilingual drupal 7
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 

Viewers also liked

R.K.Lilley - Up in air trilogy ( 2nd book "Mile High" )
R.K.Lilley - Up in air trilogy ( 2nd book "Mile High" )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 - groundedR. k. lilley   up in the air 03 - grounded
R. k. lilley up in the air 03 - groundedAricia Aguiar
 
R.K.Lilley - Up in air trilogy ( 3rd book "Grounded )
R.K.Lilley - Up in air trilogy ( 3rd book "Grounded )R.K.Lilley - Up in air trilogy ( 3rd book "Grounded )
R.K.Lilley - Up in air trilogy ( 3rd book "Grounded )
Dijana Veglia
 
تطوير المناهج وأسس تنظيمها8
تطوير المناهج وأسس تنظيمها8تطوير المناهج وأسس تنظيمها8
تطوير المناهج وأسس تنظيمها8
Magdy Aly
 
المحاضرة الأولى أسس المناهج
المحاضرة الأولى أسس المناهجالمحاضرة الأولى أسس المناهج
المحاضرة الأولى أسس المناهجasmart1987
 
اتجاهات معاصرة في تطوير المناهج
اتجاهات معاصرة في تطوير المناهجاتجاهات معاصرة في تطوير المناهج
اتجاهات معاصرة في تطوير المناهج
Heba Hoba
 
علم المناهج الدراسية 6 نظريات المنهج
علم المناهج الدراسية 6 نظريات المنهجعلم المناهج الدراسية 6 نظريات المنهج
علم المناهج الدراسية 6 نظريات المنهجyusriya aljamil
 
مهارات المذاكرة الناجحة ودخول الامتحان
مهارات المذاكرة الناجحة ودخول الامتحانمهارات المذاكرة الناجحة ودخول الامتحان
مهارات المذاكرة الناجحة ودخول الامتحان
عبدالله باخريصة
 
عرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتك
عرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتكعرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتك
عرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتك
Ahmed Rezq
 
كيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدان
كيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدانكيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدان
كيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدانMohammed Azab
 

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" )R.K.Lilley - Up in air trilogy ( 2nd book "Mile High" )
R.K.Lilley - Up in air trilogy ( 2nd book "Mile High" )
 
R. k. lilley up in the air 03 - grounded
R. k. lilley   up in the air 03 - groundedR. k. lilley   up in the air 03 - grounded
R. k. lilley up in the air 03 - grounded
 
R.K.Lilley - Up in air trilogy ( 3rd book "Grounded )
R.K.Lilley - Up in air trilogy ( 3rd book "Grounded )R.K.Lilley - Up in air trilogy ( 3rd book "Grounded )
R.K.Lilley - Up in air trilogy ( 3rd book "Grounded )
 
تطوير المناهج وأسس تنظيمها8
تطوير المناهج وأسس تنظيمها8تطوير المناهج وأسس تنظيمها8
تطوير المناهج وأسس تنظيمها8
 
المحاضرة الأولى أسس المناهج
المحاضرة الأولى أسس المناهجالمحاضرة الأولى أسس المناهج
المحاضرة الأولى أسس المناهج
 
اتجاهات معاصرة في تطوير المناهج
اتجاهات معاصرة في تطوير المناهجاتجاهات معاصرة في تطوير المناهج
اتجاهات معاصرة في تطوير المناهج
 
علم المناهج الدراسية 6 نظريات المنهج
علم المناهج الدراسية 6 نظريات المنهجعلم المناهج الدراسية 6 نظريات المنهج
علم المناهج الدراسية 6 نظريات المنهج
 
مهارات المذاكرة الناجحة ودخول الامتحان
مهارات المذاكرة الناجحة ودخول الامتحانمهارات المذاكرة الناجحة ودخول الامتحان
مهارات المذاكرة الناجحة ودخول الامتحان
 
عرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتك
عرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتكعرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتك
عرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتك
 
كتابة مقترح مشروع
كتابة مقترح مشروعكتابة مقترح مشروع
كتابة مقترح مشروع
 
كيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدان
كيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدانكيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدان
كيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدان
 

Similar to Php course-in-navimumbai

Php converted pdf
Php converted pdfPhp converted pdf
Php converted pdf
Northpole Web Service
 
Ppt php
Ppt phpPpt php
php fundamental
php fundamentalphp fundamental
php fundamental
zalatarunk
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of phppooja bhandari
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
Anshu Prateek
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
Michelangelo van Dam
 
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
rICh morrow
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
 
Modern php
Modern phpModern php
Modern php
Charles Anderson
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
Jamers2
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
ShishirKantSingh1
 
PHP - Introduction to PHP Functions
PHP -  Introduction to PHP FunctionsPHP -  Introduction to PHP Functions
PHP - Introduction to PHP Functions
Vibrant Technologies & Computers
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
jimbojsb
 

Similar to Php course-in-navimumbai (20)

Php converted pdf
Php converted pdfPhp converted pdf
Php converted pdf
 
Ppt php
Ppt phpPpt php
Ppt php
 
php fundamental
php fundamentalphp fundamental
php fundamental
 
php
phpphp
php
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
 
05php
05php05php
05php
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
 
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
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
 
Modern php
Modern phpModern php
Modern php
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
PHP - Introduction to PHP Functions
PHP -  Introduction to PHP FunctionsPHP -  Introduction to PHP Functions
PHP - Introduction to PHP Functions
 
Php
PhpPhp
Php
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 

Recently uploaded

Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

Php course-in-navimumbai

  • 1. PHP Scripting language Vibrant Technology & Computers Vashi,Navi Mumbai www.vibranttechnologies.co.in
  • 2.
  • 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