SlideShare a Scribd company logo
PHP Basic Basic  PHP  Syntax PHP  Arrays PHP  If...Else   Statements PHP  For   Loops PHP  Forms   and  User  Input PHP  Functions PHP  introduction PHP  Operators PHP -  Variables PHP  While   Loops
Basic PHP Syntax PHP code is executed on the server , and the  plain HTML  result is sent to the browser. A PHP scripting block can be placed anywhere in the document. It always starts with   <?php and ends with ?>. The example of PHP code below sends the text “Conkurent LLC” to the browser: <html>     <body>     <?php    echo &quot; Conkurent   LLC&quot;;    ?>     </body>    </html>    To make a single-line comment, use //. To make a large comment block, use /* and */. See the example below:     <html>     <body>     <?php     //This is a comment     /*   This is   a comment   block   */     ?>      </body>    </html>
PHP Arrays An  array  is a special variable that stores one or more values in a single variable. If you have a list of items, storing them in single variables could look like this: $item1=&quot;item-name1&quot;;  $item2=&quot; item-name2&quot;;  $item3=&quot; item-name3&quot;; An array can hold all your variable values under a single name. And you can access the values by referring to the array name. Each  element  in the array has its own index so that it can be easily accessed. In PHP, there are three kind of arrays: Numeric array  - An array with a numeric index  Associative array  - An array where each ID key is associated with a value  Multidimensional array  - An array containing one or more arrays
PHP If…Else Statements Conditional statements  are used to perform different actions based on different conditions. Use the if....else statement to execute some code if a condition is  true  and another code if a condition is  false . Syntax if (condition) code  to be executed if condition is  true ;  else code to be executed if condition is  false ;
The following example will output &quot;Get ready for the week!&quot; if the current day is Monday, otherwise it will output &quot;Have a good day!&quot;: <html> <body>  <?php  $d=date(&quot;D&quot;);  if ($d==&quot;Mon&quot;) echo &quot; Get ready for the week!&quot;;  else echo &quot;Have a good day!&quot;;  ?>   </body>  </html>
Use the if....elseif...else statement to select one of several blocks of code to be executed. Syntax if (condition)    code to be executed if condition is  true ;    elseif (condition)    code to be executed if condition is  true ;    else    code to be executed if condition is  false ;
PHP For Loops The  for loop  is simply a while loop with a bit more code added to it. The common tasks that are covered by a for loop are: Set a counter variable to some initial value.  Check to see if the conditional statement is true.  Execute the code within the loop.  Increment a counter at the end of each iteration through the loop.  Syntax for (init; condition; increment)  {  code to be executed;  } Parameters: init : Mostly used to set a counter (but can be any code to be executed once at the beginning of the loop)  condition : Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends.  increment : Mostly used to increment a counter (but can be any code to be executed at the end of the loop)
PHP Forms and User Input The example below contains an HTML form with two input fields and a submit button: < html >  < body >  < form  action=&quot;welcome.php&quot; method=&quot;post&quot;>  Name: < input  type=&quot;text&quot; name=&quot;fname&quot; />  Age: < input  type=&quot;text&quot; name=&quot;age&quot; />  < input  type=&quot;submit&quot; />  </ form >  </ body >  </ html >
When a user fills out the form above and clicks on the submit button, the form data is sent to a PHP file, called &quot;welcome.php&quot;, &quot;welcome.php&quot; looks like this:   <html>  <body>  Welcome  <?php  echo $_POST[&quot;fname&quot;];  ?> !<br />  You are  <?php  echo $_POST[&quot;age&quot;];  ?>  years old.  </body>  </html> Output could be something like this: Welcome John! You are 28 years old.  Notice that any form element in an HTML page will automatically be available to your PHP scripts.
PHP Functions In PHP, there are more than 700  built-in functions .  This chapter shows  how to create your own functions . A function will be executed by a call to the function. You may call a function from anywhere within a page. Syntax function  functionName() {  code to be executed;  }
To add more functionality to a function, you can add parameters. A parameter is just like a variable. Parameters are specified after the function name, inside the parentheses. To let a function return a value, use the return statement (see the example below):    <html> <body>  <? php   function  add($x,$y)  { $total=$x+$y; return $total;  }  echo &quot;6 + 9 = &quot; . add(6,9);  ?>   </body>  </html> Output: 6 + 9 = 15
Arithmetic Operators OperatorDescriptionExampleResult +Additionx=2 x+24-Subtractionx=2 5-x3*Multiplicationx=4 x*520/Division15/5 5/23 2.5%Modulus (division remainder)5%2 10%8 10%21 2 0++Incrementx=5 x++x=6--Decrementx=5 x--x=4
Ad

More Related Content

What's hot (20)

Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
Elmer Concepcion Jr.
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
Alokin Software Pvt Ltd
 
PHP
PHPPHP
PHP
Steve Fort
 
php
phpphp
php
ajeetjhajharia
 
PHP
PHPPHP
PHP
sometech
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
Shweta A
 
Php introduction
Php introductionPhp introduction
Php introduction
krishnapriya Tadepalli
 
Introduction to php web programming - get and post
Introduction to php  web programming - get and postIntroduction to php  web programming - get and post
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
PHP Loops and PHP Forms
PHP  Loops and PHP FormsPHP  Loops and PHP Forms
PHP Loops and PHP Forms
M.Zalmai Rahmani
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
Nidhi mishra
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
Pamela Fox
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Collaboration Technologies
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
Shashank Skills Academy
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web Programming
Ahmed Swilam
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
Santhiya Grace
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
Mohammed Mushtaq Ahmed
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Anjan Banda
 
PHP slides
PHP slidesPHP slides
PHP slides
Farzad Wadia
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 
Php mysql
Php mysqlPhp mysql
Php mysql
Shehrevar Davierwala
 

Viewers also liked (6)

PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
Yuriy Krapivko
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
alexjones89
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Jussi Pohjolainen
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
Muthuselvam RS
 
PHP Project PPT
PHP Project PPTPHP Project PPT
PHP Project PPT
Pankil Agrawal
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
alexjones89
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Ad

Similar to PHP Tutorials (20)

Web development
Web developmentWeb development
Web development
Seerat Bakhtawar
 
Php
PhpPhp
Php
Ajaigururaj R
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
banubabitha
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
banubabitha
 
Php
PhpPhp
Php
WAHEEDA ROOHILLAH
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
banubabitha
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
mussawir20
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0
Cathie101
 
Php
PhpPhp
Php
Deepa Lakshmi
 
Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
SanthiNivas
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
John Rowley Notes
John Rowley NotesJohn Rowley Notes
John Rowley Notes
IBAT College
 
Php intro
Php introPhp intro
Php intro
Rajesh Jha
 
Ad

PHP Tutorials

  • 1. PHP Basic Basic PHP Syntax PHP Arrays PHP If...Else Statements PHP For Loops PHP Forms and User Input PHP Functions PHP introduction PHP Operators PHP - Variables PHP While Loops
  • 2. Basic PHP Syntax PHP code is executed on the server , and the plain HTML result is sent to the browser. A PHP scripting block can be placed anywhere in the document. It always starts with <?php and ends with ?>. The example of PHP code below sends the text “Conkurent LLC” to the browser: <html>   <body>   <?php   echo &quot; Conkurent LLC&quot;;   ?>   </body>   </html>   To make a single-line comment, use //. To make a large comment block, use /* and */. See the example below:   <html>   <body>   <?php   //This is a comment   /*   This is   a comment   block   */   ?>   </body>   </html>
  • 3. PHP Arrays An array is a special variable that stores one or more values in a single variable. If you have a list of items, storing them in single variables could look like this: $item1=&quot;item-name1&quot;; $item2=&quot; item-name2&quot;; $item3=&quot; item-name3&quot;; An array can hold all your variable values under a single name. And you can access the values by referring to the array name. Each element in the array has its own index so that it can be easily accessed. In PHP, there are three kind of arrays: Numeric array - An array with a numeric index Associative array - An array where each ID key is associated with a value Multidimensional array - An array containing one or more arrays
  • 4. PHP If…Else Statements Conditional statements are used to perform different actions based on different conditions. Use the if....else statement to execute some code if a condition is true and another code if a condition is false . Syntax if (condition) code to be executed if condition is true ; else code to be executed if condition is false ;
  • 5. The following example will output &quot;Get ready for the week!&quot; if the current day is Monday, otherwise it will output &quot;Have a good day!&quot;: <html> <body> <?php $d=date(&quot;D&quot;); if ($d==&quot;Mon&quot;) echo &quot; Get ready for the week!&quot;; else echo &quot;Have a good day!&quot;; ?> </body> </html>
  • 6. Use the if....elseif...else statement to select one of several blocks of code to be executed. Syntax if (condition)   code to be executed if condition is true ;   elseif (condition)   code to be executed if condition is true ;   else   code to be executed if condition is false ;
  • 7. PHP For Loops The for loop is simply a while loop with a bit more code added to it. The common tasks that are covered by a for loop are: Set a counter variable to some initial value. Check to see if the conditional statement is true. Execute the code within the loop. Increment a counter at the end of each iteration through the loop. Syntax for (init; condition; increment) { code to be executed; } Parameters: init : Mostly used to set a counter (but can be any code to be executed once at the beginning of the loop) condition : Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends. increment : Mostly used to increment a counter (but can be any code to be executed at the end of the loop)
  • 8. PHP Forms and User Input The example below contains an HTML form with two input fields and a submit button: < html > < body > < form action=&quot;welcome.php&quot; method=&quot;post&quot;> Name: < input type=&quot;text&quot; name=&quot;fname&quot; /> Age: < input type=&quot;text&quot; name=&quot;age&quot; /> < input type=&quot;submit&quot; /> </ form > </ body > </ html >
  • 9. When a user fills out the form above and clicks on the submit button, the form data is sent to a PHP file, called &quot;welcome.php&quot;, &quot;welcome.php&quot; looks like this: <html> <body> Welcome <?php echo $_POST[&quot;fname&quot;]; ?> !<br /> You are <?php echo $_POST[&quot;age&quot;]; ?> years old. </body> </html> Output could be something like this: Welcome John! You are 28 years old. Notice that any form element in an HTML page will automatically be available to your PHP scripts.
  • 10. PHP Functions In PHP, there are more than 700 built-in functions . This chapter shows how to create your own functions . A function will be executed by a call to the function. You may call a function from anywhere within a page. Syntax function functionName() { code to be executed; }
  • 11. To add more functionality to a function, you can add parameters. A parameter is just like a variable. Parameters are specified after the function name, inside the parentheses. To let a function return a value, use the return statement (see the example below):   <html> <body> <? php function add($x,$y) { $total=$x+$y; return $total; } echo &quot;6 + 9 = &quot; . add(6,9); ?> </body> </html> Output: 6 + 9 = 15
  • 12. Arithmetic Operators OperatorDescriptionExampleResult +Additionx=2 x+24-Subtractionx=2 5-x3*Multiplicationx=4 x*520/Division15/5 5/23 2.5%Modulus (division remainder)5%2 10%8 10%21 2 0++Incrementx=5 x++x=6--Decrementx=5 x--x=4