際際滷

際際滷Share 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 IfElse 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)

Javascript
JavascriptJavascript
Javascript
Manav Prasad
Css ppt
Css pptCss ppt
Css ppt
Nidhi mishra
Php
PhpPhp
Php
Shagufta shaheen
Php
PhpPhp
Php
Ajaigururaj R
jQuery
jQueryjQuery
jQuery
Dileep Mishra
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
Karmatechnologies Pvt. Ltd.
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
Seble Nigussie
HTML
HTMLHTML
HTML
Akash Varaiya
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
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
Mayur Mudgal
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
Shweta A
Php
PhpPhp
Php
Shyam Khant
HTML, CSS and Java Scripts Basics
HTML, CSS and Java Scripts BasicsHTML, CSS and Java Scripts Basics
HTML, CSS and Java Scripts Basics
Sun Technlogies
Jquery
JqueryJquery
Jquery
Girish Srivastava
Files in php
Files in phpFiles in php
Files in php
sana mateen
Php basics
Php basicsPhp basics
Php basics
Jamshid Hashimi
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
Javascript
JavascriptJavascript
Javascript
Manav Prasad
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Jussi Pohjolainen
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog

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
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
Digital Insights - Digital Marketing Agency
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
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
John Rowley Notes
John Rowley NotesJohn Rowley Notes
John Rowley Notes
IBAT College

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 IfElse 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