basic concept of php(Gunikhan sonowal)

4,270 views

Published on

Hypertext Preprocessor Originally called “Personal Home Page Tools” Popular server-side scripting technology Open-source Anyone may view, modify and redistribute source code Supported freely by community Platform independent

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
4,270
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

basic concept of php(Gunikhan sonowal)

  1. 1. Introduction PHP: Hypertext Preprocessor Originally called “Personal Home Page Tools” Popular server-side scripting technology Open-source Anyone may view, modify and redistribute source code Supported freely by community Platform independent
  2. 2. History Started as a Perl hack in 1994 by Rasmus Lerdorf developed to PHP/FI 2.0 By 1997 up to PHP 3.0 with a new parser engine by Zeev Suraski and Andi Gutmans Version 5.2.4 is current version, rewritten by Zend to include a number of features, such as an object model Current is version 5
  3. 3. What is a PHP File? PHP files can contain text, HTML, CSS, JavaScript, and PHP code PHP code are executed on the server, and the result is returned to the browser as plain HTML PHP files have extension ".php"
  4. 4. What Can PHP Do? PHP can generate dynamic page content PHP can create, open, read, write, and close files on the server PHP can collect form data PHP can add, delete, modify data in your database PHP can restrict users to access some pages on your website PHP can encrypt data
  5. 5. Why PHP? PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) PHP is compatible with almost all servers used today (Apache, IIS, etc.) PHP supports a wide range of databases PHP is free. Download it from the official PHP resource: www.php.net PHP is easy to learn and runs efficiently on the server side
  6. 6. Basic PHP Syntax A PHP script can be placed anywhere in the document. A PHP script starts with <?php and ends with ?>: <?php // PHP code goes here ?>
  7. 7. A PHP file normally contains HTML tags, and some PHP scripting code. Below, we have an example of a simple PHP file, with a PHP script that uses a built-in PHP function "echo" to output the text "Hello World!" on a web page: <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html>
  8. 8. Comments in PHP <html> <body> <?php // This is a single line comment # This is also a single line comment /*This is a multiple lines comment block that spans over more than one line */ ?> </body> </html>
  9. 9. PHP Case Sensitivity <html> <body> <?php ECHO "Hello World!<br>"; echo "Hello World!<br>"; EcHo "Hello World!<br>"; ?> </body> </html>
  10. 10. PHP Variables Rules for PHP variables: A variable starts with the $ sign, followed by the name of the variable A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alphanumeric characters and underscores (A-z, 0-9, and _ ) Variable names are case sensitive ($y and $Y are two different variables)
  11. 11. Php variables examples <?php $x=5; // global scope function myTest() { $y=10; // local scope echo "<p>Test variables inside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; } myTest(); echo "<p>Test variables outside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; ?>
  12. 12. PHP Operators <?php $x=10; $y=6; echo ($x + $y); // outputs 16 echo ($x - $y); // outputs 4 echo ($x * $y); // outputs 60 echo ($x / $y); // outputs 1.6666666666667 echo ($x % $y); // outputs 4 ?>
  13. 13. PHP String Operators <?php $a = "Hello"; $b = $a . " world!"; echo $b; // outputs Hello world! $x="Hello"; $x .= " world!"; echo $x; // outputs Hello world! ?>
  14. 14. PHP Increment / Decrement Operators <?php $x=10; echo ++$x; // outputs 11 $y=10; echo $y++; // outputs 10 $z=5; echo --$z; // outputs 4 $i=5; echo $i--; // outputs 5 ?>
  15. 15. PHP if...else...elseif Statements <?php $t=21; if ($t<"20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>
  16. 16. PHP switch Statement <?php $favcolor="red"; switch ($favcolor) { case "red": echo "Your favorite color is red!"; break; case "blue": echo "Your favorite color is blue!"; break; case "green": echo "Your favorite color is green!"; break; default: echo "Your favorite color is neither red, blue, or green!"; } ?>
  17. 17. PHP while Loops In PHP, we have the following looping statements: while - loops through a block of code as long as the specified condition is true do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true
  18. 18. The PHP while Loop <?php $x=1; while($x<=5) { echo "The number is: $x <br>"; $x++; } ?>
  19. 19. The PHP do...while Loop <?php $x=1; do { echo "The number is: $x <br>"; $x++; } while ($x<=5) ?>
  20. 20. PHP for Loops for (init counter; test counter; increment counter) { code to be executed; } Parameters: init counter: Initialize the loop counter value test counter: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends. increment counter: Increases the loop counter value
  21. 21. Php for loops(cont'd) The PHP foreach Loop The foreach loop works only on arrays, and is used to loop through each key/value pair in an array. <?php $colors = array("red","green","blue","yellow"); foreach ($colors as $value) { echo "$value <br>"; } ?>
  22. 22. <?php PHP Functions function writeMsg() { echo "Hello world!"; } writeMsg(); // call the function ?> PHP Function Arguments <?php function familyName($fname) { echo "$fname Refsnes.<br>"; } familyName("Jani"); ?>
  23. 23. PHP Arrays <?php $cars=array("Volvo","BMW","Toyota"); echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "."; ?> In PHP, there are three types of arrays: Indexed arrays - Arrays with numeric index Associative arrays - Arrays with named keys Multidimensional arrays - Arrays containing one or more arrays
  24. 24. Array(cont'd) PHP Indexed Arrays There are two ways to create indexed arrays: 1.The index can be assigned automatically (index always starts at 0): $cars=array("Volvo","BMW","Toyota"); 2.The count() function is used to return the length (the number of elements) of an array:
  25. 25. Array(cont'd) PHP Associative Arrays Associative arrays are arrays that use named keys that you assign to them. $age=array("Peter"=>"35","Ben"=>"37","Joe"=>" 43"); <?php $age=array("Peter"=>"35","Ben"=>"37","Joe"=>" 43"); echo "Peter is " . $age['Peter'] . " years old."; ?>
  26. 26. PHP - Sort Functions For Arrays The following PHP array sort functions: sort() - sort arrays in ascending order rsort() - sort arrays in descending order asort() - sort associative arrays in ascending order, according to the value ksort() - sort associative arrays in ascending order, according to the key arsort() - sort associative arrays in descending order, according to the value krsort() - sort associative arrays in descending order, according to the key
  27. 27. PHP Form Handling PHP - A Simple HTML Form <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body> </html> Php program <html> <body> Welcome <?php echo $_POST["name"]; ?><br> Your email address is: <?php echo $_POST["email"]; ?> </body> </html>
  28. 28. Thanks you

×