Published on

Published in: Education, Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Features of PHP <ul><li>PHP stands for Hypertext Preprocessor“. It is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. </li></ul><ul><li>It is an interpreted language. </li></ul><ul><li>There are three main fields where PHP scripts are used. </li></ul><ul><li>Server side scripting </li></ul><ul><li>Command line scripting. </li></ul><ul><li>Writing client-side GUI applications.For this PHP-GTK is used. PHP-GTK is an extension for the PHP programming language that implements language bindings for GTK+. It provides an object-oriented interface to GTK+ classes and functions and greatly simplifies writing client-side cross-platform GUI applications. </li></ul>
  2. 2. <ul><li>PHP can be used on all major operating systems, including Linux, many Unix variants, Microsoft Windows, Mac OS X etc. </li></ul><ul><li>PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server and many others. </li></ul>
  3. 3. <ul><li>You also have the choice of using procedural programming or object oriented programming, or a mixture of them. </li></ul><ul><li>PHP does more than just generating dynamic web-pages. PHP's abilities includes: </li></ul><ul><ul><li>Generating images dynamically </li></ul></ul><ul><ul><li>PDF files </li></ul></ul><ul><ul><li>Flash movies </li></ul></ul><ul><ul><li>Compression </li></ul></ul><ul><ul><li>Download and upload </li></ul></ul><ul><ul><li>XML support </li></ul></ul>
  4. 4. <ul><li>PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and countless others. </li></ul><ul><li>You can also open raw network sockets and interact using any other protocol. </li></ul><ul><li>PHP has support for the WDDX complex data exchange between virtually all Web programming languages. (Support for web services) </li></ul><ul><li>PHP has support for instantiation of Java objects and using them transparently as PHP objects. You can also use CORBA extension to access remote objects. </li></ul><ul><li>e.g. You can use java classes in php. </li></ul>
  5. 5. A sample PHP script <ul><li><html> </li></ul><ul><li><head> <title>PHP Test</title> </li></ul><ul><li></head> </li></ul><ul><li><body> <?php </li></ul><ul><li>echo &quot;<p>Hello World</p>&quot;; </li></ul><ul><li>echo phpinfo(); </li></ul><ul><li>?> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul><ul><li>A call to the phpinfo() function returns a lot of useful information about your system and setup such as available predefined variables, loaded PHP modules, and configuration settings. </li></ul>
  6. 6. <ul><li>php syntaxes are similar to C. </li></ul><ul><li>php is whitespace insensitive. </li></ul><ul><li>e.g. $four = </li></ul><ul><li>2 </li></ul><ul><li>+ </li></ul><ul><li>2; </li></ul><ul><li>php is sometimes case insensitive. i.e. All variables are case sensitive. </li></ul>
  7. 7. Basics of variable <ul><li>Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive. </li></ul><ul><li>PHP is also context-sensitive like perl. </li></ul><ul><li>A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. </li></ul>
  8. 8. <ul><li>PHP provides 8 primitive data-types. </li></ul><ul><ul><li>Four scalar types: </li></ul></ul><ul><ul><li>boolean </li></ul></ul><ul><ul><li>integer </li></ul></ul><ul><ul><li>float </li></ul></ul><ul><ul><li>string </li></ul></ul><ul><ul><li>Two compound types </li></ul></ul><ul><ul><li>array </li></ul></ul><ul><ul><li>object </li></ul></ul><ul><ul><li>Two special types: </li></ul></ul><ul><ul><li>resource </li></ul></ul><ul><ul><li>NULL </li></ul></ul><ul><li>PHP,types are associated with values rather than variables. No previous declaration is needed. You can assign value to variable as and when you need it. </li></ul><ul><li>e.g. $int_var=15; </li></ul><ul><li>$str=“string1”; </li></ul>
  9. 9. <ul><li>If you want to check out the type and value of a certain variable, use var_dump() . </li></ul><ul><li>It dumps information about variable. </li></ul><ul><li><?php $b = 3.1; $c = true; var_dump($b, $c); ?> </li></ul><ul><li>o/p : </li></ul><ul><li>float(3.1) </li></ul><ul><li>bool(true) </li></ul><ul><li>If you want to get type of a variable, then use gettype(). </li></ul><ul><li>echo gettype($bool); // prints out &quot;boolean“ </li></ul><ul><li>echo gettype($str);  // prints out &quot;string“ </li></ul>
  10. 10. <ul><li>To check type of veriables in condition, separate functions are there for each type. </li></ul><ul><li>basic syntax is is_type(variable) </li></ul><ul><li>some of it are </li></ul><ul><li>is_integer </li></ul><ul><li>is_float </li></ul><ul><li>is_numeric </li></ul><ul><li>is_string </li></ul><ul><li>is_scalar </li></ul><ul><li>is_object </li></ul><ul><li>is_array </li></ul><ul><li>It returns true if variable will be of that specific type. Otherwise it returns false. </li></ul><ul><li>If you would like to force a variable to be converted to a certain type, you may either cast the variable or use the settype() function on it. It returns true on success and false on failure. </li></ul><ul><li>settype($var, &quot;integer&quot;); </li></ul>
  11. 11. <ul><li>In php, default error reporting setting allows you to use unassigned variables without errors. </li></ul><ul><li>To change this setting you should set error reporting level to E_ALL in your php.ini file. </li></ul><ul><li>error_reporting(E_ALL); </li></ul><ul><li>To check if variable is assigned a value or not, use isset($var) . </li></ul><ul><li>PHP variables are global in scope. You can use it throughout your program. </li></ul>
  12. 12. <ul><li>To define boolean variable, </li></ul><ul><li>$flag=True; </li></ul><ul><li>To define string variable, </li></ul><ul><li>$str=“string variable”; </li></ul><ul><li>String can be enclosed in double quotes, single quotes or you can also use heredoc operator. </li></ul><ul><li>$str = <<<EOF Example of string spanning multiple lines using heredoc syntax. EOF; </li></ul><ul><li>To define constant, </li></ul><ul><li>define(&quot;MAXSIZE&quot;, 100); </li></ul>
  13. 13. Operators <ul><li>Arithmetic : +,-,/,%,* </li></ul><ul><li>String . , .= </li></ul><ul><li>Assignment operators for all above operators. +=, -= etc , ++ , -- </li></ul><ul><li>Comparision </li></ul><ul><li>== , != , <> , > , >= , < , <= , === </li></ul><ul><li>=== returns true if its two operands are having the same value, and they are of the same type. </li></ul><ul><li>e.g. </li></ul><ul><li>$a=15; </li></ul><ul><li>$b=15; </li></ul><ul><li>if( $a === $b) </li></ul><ul><li>{ </li></ul><ul><li>print “Identical variables”; </li></ul><ul><li>} </li></ul>
  14. 14. <ul><li>PHP supports one execution operator: backquotes (``). </li></ul><ul><li>PHP will attempt to execute the contents of the backquotes as a system command; the output will be returned in a variable. </li></ul><ul><li><?php $output = `ls`; echo &quot;<pre>$output</pre>&quot;; </li></ul><ul><li>?> </li></ul>
  15. 15. Control Structures <ul><li>if,else,elseif </li></ul><ul><li>while,for , do..while , for , foreach , break , continue , switch </li></ul><ul><li>$i=1; </li></ul><ul><li>switch ($i) {     case 0:         print &quot;i equals 0&quot;;         break;     case 1:         print &quot;i equals 1&quot;;         break;     case 2:         print &quot;i equals 2&quot;;         break;    default :         print &quot;i equals -1&quot;; } </li></ul><ul><li>comments . </li></ul><ul><li># , // , /* */ </li></ul>