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

More Related Content

What's hot (20)

Css
CssCss
Css
shanmuga rajan
 
Bootstrap PPT by Mukesh
Bootstrap PPT by MukeshBootstrap PPT by Mukesh
Bootstrap PPT by Mukesh
Mukesh Kumar
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
Tiji Thomas
 
PHP
PHPPHP
PHP
Steve Fort
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh
 
Form Handling using PHP
Form Handling using PHPForm Handling using PHP
Form Handling using PHP
Nisa Soomro
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
Amit Tyagi
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
NexThoughts Technologies
 
Dom
DomDom
Dom
Rakshita Upadhyay
 
Php forms
Php formsPhp forms
Php forms
Anne Lee
 
CSS
CSS CSS
CSS
Sunil OS
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
Bala Narayanan
 
Advanced Cascading Style Sheets
Advanced Cascading Style SheetsAdvanced Cascading Style Sheets
Advanced Cascading Style Sheets
fantasticdigitaltools
 
HTML
HTMLHTML
HTML
chinesebilli
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
Derek Willian Stavis
 
PHP - Introduction to PHP Forms
PHP - Introduction to PHP FormsPHP - Introduction to PHP Forms
PHP - Introduction to PHP Forms
Vibrant Technologies & Computers
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
Nisa Soomro
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
Gil Fink
 
Lesson 6 php if...else...elseif statements
Lesson 6   php if...else...elseif statementsLesson 6   php if...else...elseif statements
Lesson 6 php if...else...elseif statements
MLG College of Learning, Inc
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
Priya Goyal
 

Viewers also liked (7)

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
Andrea Tarr
 
Memphis php html form processing with php
Memphis php   html form processing with phpMemphis php   html form processing with php
Memphis php html form processing with php
Joe Ferguson
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
Dhani Ahmad
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
Ashish Chamoli
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
alexjones89
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
Manish Bothra
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Jussi Pohjolainen
 
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
Andrea Tarr
 
Memphis php html form processing with php
Memphis php   html form processing with phpMemphis php   html form processing with php
Memphis php html form processing with php
Joe Ferguson
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
Dhani Ahmad
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
Ashish Chamoli
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
alexjones89
 
Ad

Similar to PHP Tutorials (20)

Web development
Web developmentWeb development
Web development
Seerat Bakhtawar
 
What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
 
Php
PhpPhp
Php
Ajaigururaj R
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
banubabitha
 
Php
PhpPhp
Php
WAHEEDA ROOHILLAH
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
banubabitha
 
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
 
What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
 
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
 
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
 
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