Your SlideShare is downloading. ×
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
PHP INTRODUCATION
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

PHP INTRODUCATION

1,399

Published on

IN THIS PPT YOU WILL FIND PHP WITH EXAMPLE

IN THIS PPT YOU WILL FIND PHP WITH EXAMPLE

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
1,399
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Introduction to PHP Introduction to PHP Pankil Agrawal Developer , PersistancePlus 1
  • 2. Introduction to PHP Introduction to PHP • PHP Hypertext Preprocessor. – Other Names : Personal Home Page, Professional Home Page • Is a server side scripting language. – Capable of generating the HTML pages • PHP is an open source software and free to download and use • PHP files have a file extension of ".php", ".php3", or ".phtml" 2
  • 3. Introduction to PHP What can PHP do .. • Server-side scripting • Command line scripting • Writing client-side GUI applications 3
  • 4. Introduction to PHP Why PHP? • ..There are no. of server side scripting available like ASP, JSP….. • PHP involves – simplicity in scripting (..generally using the database) – platform independence. – Runs on different operating systems such as Linux, Unix and Windows – Low maintenance and development cost – Compatible with servers IIS and Apache – PHP code run faster – Ability to embed into HTML code – Supports different databases such as SQL, Generic ODBC, MySQL, Oracle, Sybase etc.. – Is an open source. (www.php.net) 4
  • 5. Introduction to PHP Required Packages( For Windows) • WAMP server • Macromedia Dream Weaver 5
  • 6. Introduction to PHP WAMP Server • WAMPs are packages of independently-created programs installed on computers that use a Microsoft Windows operating system , So it is set of open source applications (WAMP stack) • WAMP" is an acronym formed from the initials of the operating system (Windows) and the package's principal components: Apache, MySQL and PHP (or Perl or Python) • The equivalent installation – Linux operating system is known as LAMP. – Mac operating system is known as MAMP. – Solaris operating system is known as SAMP Apache is a web server MySQL is a database manager 6
  • 7. Introduction to PHP Syntax • A PHP scripting block always starts with <? php and ends with ?>. • Eg: <?php?> • A PHP scripting block can be placed anywhere in the document. • A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code. 7
  • 8. Introduction to PHP "Hello World" <html> <body> <?php echo "Hello World"; ?> </body> </html> 8
  • 9. Introduction to PHP • Each code line in PHP must end with a semicolon • Caution : The file must have the .php extension. If the file has a .html extension, the PHP code will not be executed. • PHP Comments : – // to make a single-line comment – /* and */ to make a large comment block. 9
  • 10. WEB SERVER Introduction to PHP Gets Page <HTML> <?php PHP code ?> </HTML> HTTP Request (url) Server response CLIENT Hello World Interprets the PHP code <HTML> <B>Hello</B> </HTML> Browser creates the web page 10
  • 11. Introduction to PHP PHP Language features • PHP language features such as control structures, operators, variable types, function declaration, class/object declaration are almost similar to any compiled or interpreted language such as C or C++. 11
  • 12. Introduction to PHP PHP Variables • The variables in PHP are declared by appending the $ sign to the variable name. – For e.g $company = “NCST”; $sum = 10.0; • variable’s data type is changed by the value that is assigned to the variable. • PHP is a Loosely Typed Language – In a strongly typed programming language, you have to declare (define) the type and name of the variable before using it. – In PHP the variable is declared automatically when you use it. • Type casting allows to change the data type explicitly. 12
  • 13. Introduction to PHP Variable Naming Rules • A variable name must start with a letter or an underscore "_" • Can only contain alpha-numeric characters and underscores • Should not contain spaces 13
  • 14. Introduction to PHP Operators • Arithmetic (+,-,*,/,%) • Assignment (=,+=,-+,*=,/=,.=,%=) – Where x+=y will consider as x = x+y • Comparison (==,!=,<,>,<=,>=) • Logical ( && , || , !) 14
  • 15. Introduction to PHP PHP Constants • A constant is an identifier (name) for a simple value • As the name suggests, that value cannot change during the execution of the script • A valid constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores • Constants are defined in PHP by using the define() function. – For e.g. define(“NCST”, “National Centre for Software Technology”) • Only scalar data (boolean, integer, float and string) can be contained in constants 15
  • 16. Introduction to PHP PHP Data Type • PHP supports eight primitive types – Four Scalar Type • • • • boolean integer float (floating-point number, aka 'double') string – Two Compound Type • array • object – And Two Special Type • resource • NULL 16
  • 17. Introduction to PHP Example for Type checking • <?php $bool = TRUE; // a boolean $str = "foo"; // a string $int = 12; // an integer echo gettype($bool); // prints out "boolean" echo gettype($str); // prints out "string" echo gettype($int); // Print out “integer” ?> 17
  • 18. Introduction to PHP Booleans • A boolean expresses a truth value. It can be either TRUE or FALSE. • Non-zero (whether negative or positive) number! Number can consider as TRUE • <?php $foo = True; // assign the value TRUE to $foo ?> 18
  • 19. Introduction to PHP Integers • An integer is a number of the set Z = {..., -2, -1, 0, 1, 2, ...}. • Integers can be specified in decimal (10-based), hexadecimal (16-based) or octal (8-based) notation, optionally preceded by a sign (- or +). • <?php $a = 1234; # decimal number $a = -123; # a negative number $a = 0123; # octal number (equivalent to 83 decimal) $a = 0x1A; # hexadecimal number (equivalent to 26 decimal) ?> 19
  • 20. Introduction to PHP Floating point numbers • <?php $a = 1.234; $b = 1.2e3; $c = 7E-10; ?> 20
  • 21. Introduction to PHP Strings • String variables are used for values that contain character strings. • (.) Dot operator use to concatenation • Eg :<?php $txt1="Hello World"; $txt2=“Bye Bye World"; echo $txt2 . “-” . $txt2; ?> o/p  Hello World – Bye Bye world • Functions : – strlen() -> echo strlen(“hello”); (5) – Strpos()-> echo strpos(“hello world”,”world ”); (6) 21
  • 22. Introduction to PHP Arrays • An array can store one or more values in a single variable name • There are different ways to declare array.. – array( [key =>] value – // key may be an integer or string // value may be any value – Example • <?php $arr = array("foo" => "bar", 12 => true); echo $arr["foo"]; // bar echo $arr[12]; // 1 ?> 22
  • 23. Introduction to PHP Cont.. In this method id will automatically assign $names = array("Peter","Quagmire","Joe"); In this example we assign the ID key manually: $names[0] = “hello"; $names[1] = “hi"; $names[2] = “how are you”; Example <?php $names[0] = "Peter"; $names[1] = “Jen"; $names[2] = "Joe"; echo $names[1] . " and " . $names[2] . "are". $names[0] . "'s neighbors"; ?> O/p Jen and Joe are Peter's neighbors 23
  • 24. Introduction to PHP Objects • To initialize an object, you use the new statement to instantiate the object to a variable. <?php class foo { function do_foo() { echo "Doing foo."; } } $bar = new foo; $bar->do_foo(); ?> 24
  • 25. Introduction to PHP • Converting To Object – <?php $obj = (object) 'ciao'; ?> 25
  • 26. Introduction to PHP Resource • A resource is a special variable, holding a reference to an external resource • Resources are created and used by special functions – Example dba_open() • (PHP 3>= 3.0.8, PHP 4 ) • dba_open -- Open database 26
  • 27. Introduction to PHP NULL • The special NULL value represents that a variable has no value • A variable is considered to be NULL if – – – – it has been assigned the constant NULL. it has not been set to any value yet. it has been unset(). Syntax <?php $var = NULL; ?> 27
  • 28. Introduction to PHP Control Structure • • • • • • • • • • if else elseif while do..while for foreach break continue switch 28
  • 29. Introduction to PHP If..else & elseif statement • if (condition) { code to be executed if condition is true; if multiple statements , then you can use braces; } elseif (condition) code to be executed if condition is true; else code to be executed if condition is false; 29
  • 30. Introduction to PHP Example.. <html> <body> <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend!"; elseif ($d=="Sun") echo "Have a nice Sunday!"; else echo "Have a nice day!"; ?> </body> </html> 30
  • 31. Introduction to PHP While.. Syntax: while (condition) code to be executed; Example : <html> <body> <?php $i=1; while($i<=5) { echo "The number is " . $i . "<br />"; $i++; } ?> </body> </html> 31
  • 32. Introduction to PHP Do While.. Syntax: do{ code to be executed; }while (condition); Example: <html> <body> <?php $i=0; do{ $i++; echo "The number is " . $i . "<br />"; }while ($i<5); ?> </body> </html> 32
  • 33. Introduction to PHP For Syntax: for (init; cond; incr) { code to be executed; } <html> <body> <?php for ($i=1; $i<=5; $i++) { echo "Hello World!<br />"; } ?> </body> </html> 33
  • 34. Introduction to PHP foreach • The foreach statement is used to loop through arrays Syntax: foreach (array as value) { code to be executed; } Example <html> <body> <?php $arr=array("one", "two", "three"); foreach ($arr as $value) { echo "Value: " . $value . "<br />"; } ?> </body> </html> On each loop, the value of the current element is assigned to $value and the internal array pointer is advanced by one 34
  • 35. Introduction to PHP break • • break ends execution of the current for, foreach while, do..while or switch structure. break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of <?php $i = 0; while (++$i) { switch ($i) { case 5: echo "At 5<br />n"; break 1; /* Exit only the switch. */ case 10: echo "At 10; quitting<br />n"; break 2; /* Exit the switch and the while. */ default: break; } } ?> 35
  • 36. Introduction to PHP continue • continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the beginning of the next iteration. 36
  • 37. Introduction to PHP Switch • The switch statement is similar to a series of IF statements on the same expression <html> <body> <?php switch ($x) { case 1: echo "Number 1"; break; case 2: echo "Number 2"; break; case 3: echo "Number 3"; break; default: echo "No number between 1 and 3"; } ?> </body> </html> 37
  • 38. Introduction to PHP Function • User Defined Function • Built-In Function 38
  • 39. Introduction to PHP User Define Function • • • • • • All functions start with the word "function()" Name the function - It should be possible to understand what the function does by its name. The name can start with a letter or underscore (not a number) Add a "{" - The function code starts after the opening curly brace Insert the function code Add a "}" - The function is finished by a closing curly brace Example: <?php function writeMyName() { echo “hardik"; } writeMyName(); ?> 39
  • 40. Introduction to PHP Function with Parameter <?php function writeMyName($fname) { echo $fname; } echo "My name is "; writeMyName(“Hardik"); echo “I like "; writeMyName(“PHP"); ?> 40
  • 41. Introduction to PHP Function with return value <?php function add($x,$y) { $total = $x + $y; return $total; } echo "1 + 16 = " . add(1,16); ?> 41
  • 42. Introduction to PHP Encrypting string <?php $password = “hardik”; md5($password)); ?> 42
  • 43. Introduction to PHP THANK YOU Mail Me Pankil@persistanceplus.com 43

×