SlideShare une entreprise Scribd logo
1  sur  16
VIJAY SHARMA
PHP TUTORIAL
PHP Programming
With
My SQL Connection
www.kumarvijaybaswa.blogspot.com
VIJAY SHARMA
PHP: The Basics
 Why PHP and MySQL?
VIJAY SHARMA
What Is PHP?
 PHP is the Web development language written by and for Web
developers.
 PHP stands for PHP: Hypertext Preprocessor. The product was
originally named Personal Home Page Tools, and many people still
think that’s what the acronym stands for. But as it expanded in scope,
a new and more appropriate name was selected by community vote.
PHP is currently in its fifth major rewrite, called PHP5 or just plain
PHP.
VIJAY SHARMA
Server-Side Scripting
 A “script” is a collection of program or sequence of instructions that is
interpreted or carried out by another program rather than by the computer
processor.
 Client-side
 Server-side
 In server-side scripting, (such as PHP, ASP) the script is processed by the
server Like: Apache, ColdFusion, ISAPI and Microsoft's IIS on Windows.
 Client-side scripting such as JavaScript runs on the web browser.
VIJAY SHARMA
Advantages of Server-Side Scripting
 Dynamic content.
 Computational capability.
 Database and file system access.
 Network access (from the server only).
 Built-in libraries and functions.
 Known platform for execution (as opposed
to client-side,
 where the platform is uncontrolled.)
 Security improvements
VIJAY SHARMA
INTRODUCTION TO PHP
 PHP stands for PHP: Hypertext Preprocessor
 Developed by Rasmus Lerdorf in 1994
 It is a powerful server-side scripting language for creating
dynamic and interactive websites.
 It is an open source software, which is widely used and free to
download and use (PHP is FREE to download from the official
PHP resource: www.php.net).
 It is an efficient alternative to competitors such as Microsoft's
ASP.
VIJAY SHARMA
 PHP is perfectly suited for Web development and can be
embedded directly into the HTML code.
 The PHP syntax is very similar to JavaScript, Perl and C.
 PHP is often used together with Apache (web server) on
various operating systems. It also supports ISAPI and can
be used with Microsoft's IIS on Windows.
 PHP supports many databases (MySQL, Informix, Oracle,
Sybase,
 Solid, PostgreSQL, Generic ODBC, etc.)
INTRODUCTION TO PHP
VIJAY SHARMA
What is a PHP File?
 PHP files have a file extension of ".php", ".php3", or
".phtml"
 PHP files can contain text, HTML tags and scripts
 PHP files are returned to the browser as plain HTML
INTRODUCTION TO PHP
VIJAY SHARMA
What you need to develop PHP Application:
 Install Apache (or IIS) on your own server, install PHP, and
MySQL
 Install Wampserver2 or XAMPP (a bundle of PHP,
Apache, and MySql server) on your own server/machine
INTRODUCTION TO PHP
VIJAY SHARMA
PHP Syntax
 A PHP scripting block always starts
with <?php and ends with ?>
 <?php……………. ?>
VIJAY SHARMA
Example simple html & php page
 PHP and HTML Code:
<html>
<head>
<title>My First PHP Page
</title>
</head>
<body>
<?php
echo "Hello World!";
?>
</body> </html>
VIJAY SHARMA
PHP VARIABLES
 Variables are used for storing values, such as
numbers, strings or function results, so that they can
be used many times in a script.
 All variables in PHP start with a $ sign symbol.
 Variables are assigned using the assignment
operator "=“
 Variable names are case sensitive in PHP:
 $name is not the same as $NAME or $Name.
 In PHP a variable does not need to be declared before
being set.
 PHP is a Loosely Typed Language.
VIJAY SHARMA
Example:
 <?php
 $var1 = 'PHP'; // Assigns a
value of 'PHP' to $var1
 $var2 = 5; // Assigns a value
of 5 to $var2
 $var3 = $var2 + 1; // Assigns
a value of 6 to $var3
 $var2 = $var1; // Assigns a
value of 'PHP' to $var2
 echo $var1; // Outputs 'PHP‘
 echo "<br />";
 echo $var2; // Outputs 'PHP'
 echo "<br />";
 echo $var3; // Outputs '6'
 echo "<br />";
 echo $var1 . ' rules!'; //
Outputs 'PHP rules!'
 echo "$var1 rules!"; //
Outputs 'PHP rules!'
 echo '$var1 rules!'; // Outputs
'$var1 rules!‘
 ?>
VIJAY SHARMA
VARIABLE SCOPE AND LIFETIME
 The scope of a variable defined within a
function is local to that function.
 A variable defined in the main body of code
has a global scope.
 If a function needs to use a variable that is
defined in the main body of the program, it
must reference it using the "global"
keyword, like this:
VIJAY SHARMA
Example:
 <?php
 function mul()
 {
 global $start;
 print "<tr>";
 for ($num=1; $num <= 10; $num++ )
 {
 $cell = $num * $start;
 print "<td> " . $cell . " </td>";
 }
 print "</tr>";
 }
 $start = 0;
VIJAY SHARMA
 print "<table border=1
cellpadding=3>";
 while ( $start <=10 )
 {
 mul();
 $start++;
 }
 print "</table>";
 ?>

Contenu connexe

Tendances (20)

Php basics
Php basicsPhp basics
Php basics
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Lesson 2 php data types
Lesson 2   php data typesLesson 2   php data types
Lesson 2 php data types
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php
PhpPhp
Php
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
php
phpphp
php
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
Php mysql
Php mysqlPhp mysql
Php mysql
 

En vedette

Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Hitesh Patel
 
Phpbasics And Php Framework
Phpbasics And Php FrameworkPhpbasics And Php Framework
Phpbasics And Php Frameworkshivas
 
Joomla @ Barcamp4(Feb 08 Pune)
Joomla @ Barcamp4(Feb 08 Pune)Joomla @ Barcamp4(Feb 08 Pune)
Joomla @ Barcamp4(Feb 08 Pune)Amit Kumar Singh
 
PHP framework difference
PHP framework differencePHP framework difference
PHP framework differenceiScripts
 
PHP Framework
PHP FrameworkPHP Framework
PHP Frameworkceleroo
 
How to learn to build your own PHP framework
How to learn to build your own PHP frameworkHow to learn to build your own PHP framework
How to learn to build your own PHP frameworkDinh Pham
 
Tutorial php membuat Aplikasi Inventaris
Tutorial php membuat Aplikasi InventarisTutorial php membuat Aplikasi Inventaris
Tutorial php membuat Aplikasi InventarisDeka M Wildan
 
Tutorial Pembuatan Aplikasi Website Beserta Databasenya
Tutorial Pembuatan Aplikasi Website Beserta DatabasenyaTutorial Pembuatan Aplikasi Website Beserta Databasenya
Tutorial Pembuatan Aplikasi Website Beserta DatabasenyaRCH_98
 

En vedette (11)

Best Practices for Mobile Web Design
Best Practices for Mobile Web DesignBest Practices for Mobile Web Design
Best Practices for Mobile Web Design
 
Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12
 
Phpbasics And Php Framework
Phpbasics And Php FrameworkPhpbasics And Php Framework
Phpbasics And Php Framework
 
Joomla @ Barcamp4(Feb 08 Pune)
Joomla @ Barcamp4(Feb 08 Pune)Joomla @ Barcamp4(Feb 08 Pune)
Joomla @ Barcamp4(Feb 08 Pune)
 
PHP framework difference
PHP framework differencePHP framework difference
PHP framework difference
 
SQL -PHP Tutorial
SQL -PHP TutorialSQL -PHP Tutorial
SQL -PHP Tutorial
 
PHP Framework
PHP FrameworkPHP Framework
PHP Framework
 
How to learn to build your own PHP framework
How to learn to build your own PHP frameworkHow to learn to build your own PHP framework
How to learn to build your own PHP framework
 
Tutorial php membuat Aplikasi Inventaris
Tutorial php membuat Aplikasi InventarisTutorial php membuat Aplikasi Inventaris
Tutorial php membuat Aplikasi Inventaris
 
PHP MVC
PHP MVCPHP MVC
PHP MVC
 
Tutorial Pembuatan Aplikasi Website Beserta Databasenya
Tutorial Pembuatan Aplikasi Website Beserta DatabasenyaTutorial Pembuatan Aplikasi Website Beserta Databasenya
Tutorial Pembuatan Aplikasi Website Beserta Databasenya
 

Similaire à Php tutorial (20)

Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
 
Php
PhpPhp
Php
 
php basics
php basicsphp basics
php basics
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Upstate CSCI 450 PHP
Upstate CSCI 450 PHPUpstate CSCI 450 PHP
Upstate CSCI 450 PHP
 
Lecture8
Lecture8Lecture8
Lecture8
 
Php hypertext pre-processor
Php   hypertext pre-processorPhp   hypertext pre-processor
Php hypertext pre-processor
 
Php unit i
Php unit iPhp unit i
Php unit i
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Prersentation
PrersentationPrersentation
Prersentation
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessor
 
Php notes
Php notesPhp notes
Php notes
 
PHP Basics Ebook
PHP Basics EbookPHP Basics Ebook
PHP Basics Ebook
 
phptutorial
phptutorialphptutorial
phptutorial
 
phptutorial
phptutorialphptutorial
phptutorial
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Php
PhpPhp
Php
 

Plus de Computer Hardware & Trouble shooting (7)

Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
Vlsm
VlsmVlsm
Vlsm
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
 
Storing data : Disk Organization and I/O
Storing data : Disk Organization and I/OStoring data : Disk Organization and I/O
Storing data : Disk Organization and I/O
 
Mcse question
Mcse questionMcse question
Mcse question
 
Css notes
Css notesCss notes
Css notes
 
File organization
File organizationFile organization
File organization
 

Dernier

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 

Dernier (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

Php tutorial

  • 1. VIJAY SHARMA PHP TUTORIAL PHP Programming With My SQL Connection www.kumarvijaybaswa.blogspot.com
  • 2. VIJAY SHARMA PHP: The Basics  Why PHP and MySQL?
  • 3. VIJAY SHARMA What Is PHP?  PHP is the Web development language written by and for Web developers.  PHP stands for PHP: Hypertext Preprocessor. The product was originally named Personal Home Page Tools, and many people still think that’s what the acronym stands for. But as it expanded in scope, a new and more appropriate name was selected by community vote. PHP is currently in its fifth major rewrite, called PHP5 or just plain PHP.
  • 4. VIJAY SHARMA Server-Side Scripting  A “script” is a collection of program or sequence of instructions that is interpreted or carried out by another program rather than by the computer processor.  Client-side  Server-side  In server-side scripting, (such as PHP, ASP) the script is processed by the server Like: Apache, ColdFusion, ISAPI and Microsoft's IIS on Windows.  Client-side scripting such as JavaScript runs on the web browser.
  • 5. VIJAY SHARMA Advantages of Server-Side Scripting  Dynamic content.  Computational capability.  Database and file system access.  Network access (from the server only).  Built-in libraries and functions.  Known platform for execution (as opposed to client-side,  where the platform is uncontrolled.)  Security improvements
  • 6. VIJAY SHARMA INTRODUCTION TO PHP  PHP stands for PHP: Hypertext Preprocessor  Developed by Rasmus Lerdorf in 1994  It is a powerful server-side scripting language for creating dynamic and interactive websites.  It is an open source software, which is widely used and free to download and use (PHP is FREE to download from the official PHP resource: www.php.net).  It is an efficient alternative to competitors such as Microsoft's ASP.
  • 7. VIJAY SHARMA  PHP is perfectly suited for Web development and can be embedded directly into the HTML code.  The PHP syntax is very similar to JavaScript, Perl and C.  PHP is often used together with Apache (web server) on various operating systems. It also supports ISAPI and can be used with Microsoft's IIS on Windows.  PHP supports many databases (MySQL, Informix, Oracle, Sybase,  Solid, PostgreSQL, Generic ODBC, etc.) INTRODUCTION TO PHP
  • 8. VIJAY SHARMA What is a PHP File?  PHP files have a file extension of ".php", ".php3", or ".phtml"  PHP files can contain text, HTML tags and scripts  PHP files are returned to the browser as plain HTML INTRODUCTION TO PHP
  • 9. VIJAY SHARMA What you need to develop PHP Application:  Install Apache (or IIS) on your own server, install PHP, and MySQL  Install Wampserver2 or XAMPP (a bundle of PHP, Apache, and MySql server) on your own server/machine INTRODUCTION TO PHP
  • 10. VIJAY SHARMA PHP Syntax  A PHP scripting block always starts with <?php and ends with ?>  <?php……………. ?>
  • 11. VIJAY SHARMA Example simple html & php page  PHP and HTML Code: <html> <head> <title>My First PHP Page </title> </head> <body> <?php echo "Hello World!"; ?> </body> </html>
  • 12. VIJAY SHARMA PHP VARIABLES  Variables are used for storing values, such as numbers, strings or function results, so that they can be used many times in a script.  All variables in PHP start with a $ sign symbol.  Variables are assigned using the assignment operator "=“  Variable names are case sensitive in PHP:  $name is not the same as $NAME or $Name.  In PHP a variable does not need to be declared before being set.  PHP is a Loosely Typed Language.
  • 13. VIJAY SHARMA Example:  <?php  $var1 = 'PHP'; // Assigns a value of 'PHP' to $var1  $var2 = 5; // Assigns a value of 5 to $var2  $var3 = $var2 + 1; // Assigns a value of 6 to $var3  $var2 = $var1; // Assigns a value of 'PHP' to $var2  echo $var1; // Outputs 'PHP‘  echo "<br />";  echo $var2; // Outputs 'PHP'  echo "<br />";  echo $var3; // Outputs '6'  echo "<br />";  echo $var1 . ' rules!'; // Outputs 'PHP rules!'  echo "$var1 rules!"; // Outputs 'PHP rules!'  echo '$var1 rules!'; // Outputs '$var1 rules!‘  ?>
  • 14. VIJAY SHARMA VARIABLE SCOPE AND LIFETIME  The scope of a variable defined within a function is local to that function.  A variable defined in the main body of code has a global scope.  If a function needs to use a variable that is defined in the main body of the program, it must reference it using the "global" keyword, like this:
  • 15. VIJAY SHARMA Example:  <?php  function mul()  {  global $start;  print "<tr>";  for ($num=1; $num <= 10; $num++ )  {  $cell = $num * $start;  print "<td> " . $cell . " </td>";  }  print "</tr>";  }  $start = 0;
  • 16. VIJAY SHARMA  print "<table border=1 cellpadding=3>";  while ( $start <=10 )  {  mul();  $start++;  }  print "</table>";  ?>