SlideShare a Scribd company logo
1 of 24
PHP             (BASIC)




First session
INDEX




•   Into        •   Do … while loop
•   Syntax      •   While loop
•   Variables   •   For loop
•   String      •   Functions
•   Operators   •   Form
•   If else     •   $_POST
•   Switch      •   $_GET
•   Array       •   $_REQUEST
INTRO   • What is PHP?

        • What is MySQL?

        • Why PHP?
PHP SYNTAX   •   Extension
             •   First file name
             •   Where shall we save the project
             •   <?php           ?>



             • <html><body>
             • <?php echo "Hello World"; ?>
             • </body></html>

             • Comments in PHP
VARIABLES   • Creating (Declaring) PHP Variables
            • $myName=“Doksh";
            • PHP has four different variable scopes:

            •   local
            •   global
            •   static
            •   parameter
LOCAL   • <?php
        • $a = 5; // global scope

        •   function myTest()
        •   {
        •   echo $a; // local scope
        •   }

        • myTest();
        • ?>
GLOBAL   • <?php
         • $a = 5;
         • $b = 10;

         •   function myProject()
         •   {
         •   global $a, $b;
         •   $b = $a + $b;
         •   }

         • myProject();
         • echo $b;
         • ?>
STATIC SCOPE   • static $rememberMe;

AND            •   function myTest($a1,$a2,...)
PARAMETERS
               •   {
               •   // function code
               •   }
STRING         •   <?php
VARIABLES IN   •   $txt="Hello World";
PHP            •   echo $txt;
               •   ?>

               • concatenation operator

               • echo $txt1 . " " . $txt2;
STRLEN()   • <?php
FUNCTION   • echo strlen("Hello world!");
&          • ?>
STRPOS()
              ______________________________
FUNCTION

           <?php
           echo strpos("Hello world!","world");
           ?>
OPERATORS   •   +
            •   -
            •   *
            •   /
            •   %
            •   -m
            •   M.m
            •   X=y
            •   X +=y …. etc
            •   ++x per
            •   X++ post
            •   X == y, X != y
            •   X === y, X !== y
            •   X >= y, X >y
            •   X && y
            •   X  y
IF & DATE   •   <html>
            •   <body>

            •   <?php
            •   $d=date("D");
            •   if ($d=="Fri")
            •     {
            •     echo “WOW";
            •     }
            •   elseif ($d=="Sun")
            •     {
            •     echo “OK OK OK OK";
            •     }
            •   else
            •     {
            •     echo “ohhhh!";
            •     }
            •   ?>

            •   </body>
            •   </html>
SWITCH   •   <html>
         •   <body>

         •   <?php
         •   $x=1;
         •   switch ($x)
         •   {
         •   case 1:
         •     echo "Number 1";
         •     break;
         •   case 2:
         •     echo "Number 2";
         •     break;
         •   case 3:
         •     echo "Number 3";
         •     break;
         •   default:
         •     echo "No number ";
         •   }
         •   ?>

         •   </body>
ARRAY   • $Name=array(“Moha",“Tom",“Totti",“
          Nona");

        •   <?php
        •   $Name[0]=“Moha";
        •   $Name[1]=“Tom";
        •   $Name[2]=“Totti";
        •   $Name[3]=“Nona";
        •   echo $Name[0] . " and " . $ Name[1];
        •   ?>
WHILE   • <html>
        • <body>

        •   <?php
        •   $i=1;
        •   while($i<=5)
        •    {
        •    echo "The number is " . $i . "<br />";
        •    $i++;
        •    }
        •   ?>

        • </body>
        • </html>
DO WHILE   •   <html>
           •   <body>

           •   <?php
           •   $i=1;
           •   do
           •    {
           •    $i++;
           •    echo "The number is " . $i . "<br />";
           •    }
           •   while ($i<=5);
           •   ?>

           •   </body>
           •   </html
FOR   • <html>
      • <body>

      • <?php
      • for ($i=1; $i<=5; $i++)
      • {
      • echo "The number is " . $i . "<br />";
      • }
      • ?>

      • </body>
      • </html>
FUNCTION   •   <html>
           •   <body>

           •   <?php
           •   function writeName()
           •   {
           •   echo “Mohammed";
           •   }

           •   echo "My name is ";
           •   writeName();
           •   ?>

           •   </body>
           •   </html>
•
FUNCTION   •
               <html>
               <body>

           •   <?php
           •   function writeName($fname,$punctuation)
           •   {
           •   echo $fname . " Refsnes" . $punctuation . "<br />";
           •   }

           •   echo "My name is ";
           •   writeName(“Moha,".");
           •   echo "My sister's name is ";
           •   writeName(“nona","!");
           •   echo "My brother's name is ";
           •   writeName(“amjad","?");
           •   ?>

           •   </body>
           •   </html>
FUNCTION   •   <html>
           •   <body>

           •   <?php
           •   function add($x,$y)
           •   {
           •   $total=$x+$y;
           •   return $total;
           •   }

           •   echo "1 + 16 = " . add(1,16);
           •   ?>

           •   </body>
           •   </html>
FORM   • <html>
       • <body>

       • <form action="welcome.php"
         method="post">
       • Name: <input type="text"
         name="fname" />
       • Age: <input type="text" name="age" />
       • <input type="submit" />
       • </form>

       • </body>
       • </html>
FORM   • <html>
       • <body>
&
POST
       • Welcome <?php echo $_POST["fname"];
         ?>!<br />
       • You are <?php echo $_POST["age"]; ?>
         years old.

       • </body>
       • </html>
GET   • <form action="welcome.php"
        method="get">
      • Name: <input type="text"
        name="fname" />
      • Age: <input type="text" name="age" />
      • <input type="submit" />
      • </form>

      • Welcome <?php echo $_GET["fname"];
        ?>.<br />
      • You are <?php echo $_GET["age"]; ?>
        years old!
REQUEST   • Welcome <?php echo
            $_REQUEST["fname"]; ?>!<br />
          • You are <?php echo $_REQUEST["age"];
            ?> years old.

More Related Content

What's hot

The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type Systemabrummett
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodJeremy Kendall
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of SmartmatchAndrew Shitov
 
(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and ProfitOlaf Alders
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPJeremy Kendall
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPJeremy Kendall
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic trapsDamien Seguy
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlordsheumann
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackVic Metcalfe
 
DPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark WorkshopDPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark WorkshopJeroen Keppens
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6garux
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language TriviaNikita Popov
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perlgarux
 
Top 10 php classic traps php serbia
Top 10 php classic traps php serbiaTop 10 php classic traps php serbia
Top 10 php classic traps php serbiaDamien Seguy
 
R57shell
R57shellR57shell
R57shellady36
 

What's hot (20)

Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
Wsomdp
WsomdpWsomdp
Wsomdp
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the Good
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of Smartmatch
 
(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
DPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark WorkshopDPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark Workshop
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language Trivia
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perl
 
Top 10 php classic traps php serbia
Top 10 php classic traps php serbiaTop 10 php classic traps php serbia
Top 10 php classic traps php serbia
 
R57shell
R57shellR57shell
R57shell
 
Perl5i
Perl5iPerl5i
Perl5i
 

Viewers also liked

Els nous mitjans
Els nous mitjansEls nous mitjans
Els nous mitjansxamara
 
SharePoint 2010 Sandboxed Solution
SharePoint 2010 Sandboxed SolutionSharePoint 2010 Sandboxed Solution
SharePoint 2010 Sandboxed SolutionSrini Sistla
 
PHP for HTML Gurus - J and Beyond 2012
PHP for HTML Gurus - J and Beyond 2012PHP for HTML Gurus - J and Beyond 2012
PHP for HTML Gurus - J and Beyond 2012Andrea Tarr
 

Viewers also liked (6)

Php basics
Php basicsPhp basics
Php basics
 
Android ui with xml
Android ui with xmlAndroid ui with xml
Android ui with xml
 
Els nous mitjans
Els nous mitjansEls nous mitjans
Els nous mitjans
 
SharePoint 2010 Sandboxed Solution
SharePoint 2010 Sandboxed SolutionSharePoint 2010 Sandboxed Solution
SharePoint 2010 Sandboxed Solution
 
A few words about WAMP
A few words about WAMPA few words about WAMP
A few words about WAMP
 
PHP for HTML Gurus - J and Beyond 2012
PHP for HTML Gurus - J and Beyond 2012PHP for HTML Gurus - J and Beyond 2012
PHP for HTML Gurus - J and Beyond 2012
 

Similar to PHP 1

Similar to PHP 1 (20)

PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
Wt unit 4 server side technology-2
Wt unit 4 server side technology-2Wt unit 4 server side technology-2
Wt unit 4 server side technology-2
 
Secure PHP Coding - Part 1
Secure PHP Coding - Part 1Secure PHP Coding - Part 1
Secure PHP Coding - Part 1
 
Synapseindia reviews on array php
Synapseindia reviews on array phpSynapseindia reviews on array php
Synapseindia reviews on array php
 
3 php forms
3 php forms3 php forms
3 php forms
 
PHP
PHPPHP
PHP
 
php (Hypertext Preprocessor)
php (Hypertext Preprocessor)php (Hypertext Preprocessor)
php (Hypertext Preprocessor)
 
Overview changes in PHP 5.4
Overview changes in PHP 5.4Overview changes in PHP 5.4
Overview changes in PHP 5.4
 
Java script programs
Java script programsJava script programs
Java script programs
 
INTRODUCTION to php.pptx
INTRODUCTION to php.pptxINTRODUCTION to php.pptx
INTRODUCTION to php.pptx
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHP
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
FizzBuzzではじめるテスト
FizzBuzzではじめるテストFizzBuzzではじめるテスト
FizzBuzzではじめるテスト
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
 
05php
05php05php
05php
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 

Recently uploaded

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

PHP 1

  • 1. PHP (BASIC) First session
  • 2. INDEX • Into • Do … while loop • Syntax • While loop • Variables • For loop • String • Functions • Operators • Form • If else • $_POST • Switch • $_GET • Array • $_REQUEST
  • 3. INTRO • What is PHP? • What is MySQL? • Why PHP?
  • 4. PHP SYNTAX • Extension • First file name • Where shall we save the project • <?php ?> • <html><body> • <?php echo "Hello World"; ?> • </body></html> • Comments in PHP
  • 5. VARIABLES • Creating (Declaring) PHP Variables • $myName=“Doksh"; • PHP has four different variable scopes: • local • global • static • parameter
  • 6. LOCAL • <?php • $a = 5; // global scope • function myTest() • { • echo $a; // local scope • } • myTest(); • ?>
  • 7. GLOBAL • <?php • $a = 5; • $b = 10; • function myProject() • { • global $a, $b; • $b = $a + $b; • } • myProject(); • echo $b; • ?>
  • 8. STATIC SCOPE • static $rememberMe; AND • function myTest($a1,$a2,...) PARAMETERS • { • // function code • }
  • 9. STRING • <?php VARIABLES IN • $txt="Hello World"; PHP • echo $txt; • ?> • concatenation operator • echo $txt1 . " " . $txt2;
  • 10. STRLEN() • <?php FUNCTION • echo strlen("Hello world!"); & • ?> STRPOS() ______________________________ FUNCTION <?php echo strpos("Hello world!","world"); ?>
  • 11. OPERATORS • + • - • * • / • % • -m • M.m • X=y • X +=y …. etc • ++x per • X++ post • X == y, X != y • X === y, X !== y • X >= y, X >y • X && y • X y
  • 12. IF & DATE • <html> • <body> • <?php • $d=date("D"); • if ($d=="Fri") • { • echo “WOW"; • } • elseif ($d=="Sun") • { • echo “OK OK OK OK"; • } • else • { • echo “ohhhh!"; • } • ?> • </body> • </html>
  • 13. SWITCH • <html> • <body> • <?php • $x=1; • switch ($x) • { • case 1: • echo "Number 1"; • break; • case 2: • echo "Number 2"; • break; • case 3: • echo "Number 3"; • break; • default: • echo "No number "; • } • ?> • </body>
  • 14. ARRAY • $Name=array(“Moha",“Tom",“Totti",“ Nona"); • <?php • $Name[0]=“Moha"; • $Name[1]=“Tom"; • $Name[2]=“Totti"; • $Name[3]=“Nona"; • echo $Name[0] . " and " . $ Name[1]; • ?>
  • 15. WHILE • <html> • <body> • <?php • $i=1; • while($i<=5) • { • echo "The number is " . $i . "<br />"; • $i++; • } • ?> • </body> • </html>
  • 16. DO WHILE • <html> • <body> • <?php • $i=1; • do • { • $i++; • echo "The number is " . $i . "<br />"; • } • while ($i<=5); • ?> • </body> • </html
  • 17. FOR • <html> • <body> • <?php • for ($i=1; $i<=5; $i++) • { • echo "The number is " . $i . "<br />"; • } • ?> • </body> • </html>
  • 18. FUNCTION • <html> • <body> • <?php • function writeName() • { • echo “Mohammed"; • } • echo "My name is "; • writeName(); • ?> • </body> • </html>
  • 19. • FUNCTION • <html> <body> • <?php • function writeName($fname,$punctuation) • { • echo $fname . " Refsnes" . $punctuation . "<br />"; • } • echo "My name is "; • writeName(“Moha,"."); • echo "My sister's name is "; • writeName(“nona","!"); • echo "My brother's name is "; • writeName(“amjad","?"); • ?> • </body> • </html>
  • 20. FUNCTION • <html> • <body> • <?php • function add($x,$y) • { • $total=$x+$y; • return $total; • } • echo "1 + 16 = " . add(1,16); • ?> • </body> • </html>
  • 21. FORM • <html> • <body> • <form action="welcome.php" method="post"> • Name: <input type="text" name="fname" /> • Age: <input type="text" name="age" /> • <input type="submit" /> • </form> • </body> • </html>
  • 22. FORM • <html> • <body> & POST • Welcome <?php echo $_POST["fname"]; ?>!<br /> • You are <?php echo $_POST["age"]; ?> years old. • </body> • </html>
  • 23. GET • <form action="welcome.php" method="get"> • Name: <input type="text" name="fname" /> • Age: <input type="text" name="age" /> • <input type="submit" /> • </form> • Welcome <?php echo $_GET["fname"]; ?>.<br /> • You are <?php echo $_GET["age"]; ?> years old!
  • 24. REQUEST • Welcome <?php echo $_REQUEST["fname"]; ?>!<br /> • You are <?php echo $_REQUEST["age"]; ?> years old.