SlideShare uma empresa Scribd logo
1 de 28
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….

Mais conteúdo relacionado

Mais procurados

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 LithiumNate Abele
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of LithiumNate Abele
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)Win Yu
 
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.3Matthew 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 PimpleHugo Hamon
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of LithiumNate Abele
 
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 FrameworksNate 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, ItalyPatrick Allaert
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language TriviaNikita 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 PHPersistenceHugo Hamon
 

Mais procurados (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
 

Destaque

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
تطوير المناهج وأسس تنظيمها8Magdy Aly
 
المحاضرة الأولى أسس المناهج
المحاضرة الأولى أسس المناهجالمحاضرة الأولى أسس المناهج
المحاضرة الأولى أسس المناهجasmart1987
 
اتجاهات معاصرة في تطوير المناهج
اتجاهات معاصرة في تطوير المناهجاتجاهات معاصرة في تطوير المناهج
اتجاهات معاصرة في تطوير المناهجHeba Hoba
 
علم المناهج الدراسية 6 نظريات المنهج
علم المناهج الدراسية 6 نظريات المنهجعلم المناهج الدراسية 6 نظريات المنهج
علم المناهج الدراسية 6 نظريات المنهجyusriya aljamil
 
مهارات المذاكرة الناجحة ودخول الامتحان
مهارات المذاكرة الناجحة ودخول الامتحانمهارات المذاكرة الناجحة ودخول الامتحان
مهارات المذاكرة الناجحة ودخول الامتحانعبدالله باخريصة
 
عرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتك
عرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتكعرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتك
عرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتكAhmed Rezq
 
كيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدان
كيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدانكيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدان
كيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدانMohammed Azab
 

Destaque (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 نظريات المنهج
 
مهارات المذاكرة الناجحة ودخول الامتحان
مهارات المذاكرة الناجحة ودخول الامتحانمهارات المذاكرة الناجحة ودخول الامتحان
مهارات المذاكرة الناجحة ودخول الامتحان
 
عرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتك
عرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتكعرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتك
عرض بوربوينت دورة كيف تدير ذاتك وتقود رحلة حياتك
 
كتابة مقترح مشروع
كتابة مقترح مشروعكتابة مقترح مشروع
كتابة مقترح مشروع
 
كيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدان
كيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدانكيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدان
كيف تكتب خطة تشغيلية لمنظمة - د. طارق السويدان
 

Semelhante a Php course-in-navimumbai

Semelhante a Php course-in-navimumbai (20)

Ppt php
Ppt phpPpt php
Ppt php
 
Php converted pdf
Php converted pdfPhp converted pdf
Php converted pdf
 
php fundamental
php fundamentalphp fundamental
php fundamental
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
 
php
phpphp
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 (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)
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 

Último

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Último (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

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