• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Php1
 

Php1

on

  • 866 views

 

Statistics

Views

Total Views
866
Views on SlideShare
866
Embed Views
0

Actions

Likes
1
Downloads
14
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Php1 Php1 Presentation Transcript

    • Features of PHP
      • 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.
      • It is an interpreted language.
      • There are three main fields where PHP scripts are used.
      • Server side scripting
      • Command line scripting.
      • 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.
      • PHP can be used on all major operating systems, including Linux, many Unix variants, Microsoft Windows, Mac OS X etc.
      • 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.
      • You also have the choice of using procedural programming or object oriented programming, or a mixture of them.
      • PHP does more than just generating dynamic web-pages. PHP's abilities includes:
        • Generating images dynamically
        • PDF files
        • Flash movies
        • Compression
        • Download and upload
        • XML support
      • 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.
      • You can also open raw network sockets and interact using any other protocol.
      • PHP has support for the WDDX complex data exchange between virtually all Web programming languages. (Support for web services)
      • 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.
      • e.g. You can use java classes in php.
    • A sample PHP script
      • <html>
      • <head> <title>PHP Test</title>
      • </head>
      • <body> <?php
      • echo &quot;<p>Hello World</p>&quot;;
      • echo phpinfo();
      • ?>
      • </body>
      • </html>
      • 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.
      • php syntaxes are similar to C.
      • php is whitespace insensitive.
      • e.g. $four =
      • 2
      • +
      • 2;
      • php is sometimes case insensitive. i.e. All variables are case sensitive.
    • Basics of variable
      • Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.
      • PHP is also context-sensitive like perl.
      • A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
      • PHP provides 8 primitive data-types.
        • Four scalar types:
        • boolean
        • integer
        • float
        • string
        • Two compound types
        • array
        • object
        • Two special types:
        • resource
        • NULL
      • 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.
      • e.g. $int_var=15;
      • $str=“string1”;
      • If you want to check out the type and value of a certain variable, use var_dump() .
      • It dumps information about variable.
      • <?php $b = 3.1; $c = true; var_dump($b, $c); ?>
      • o/p :
      • float(3.1)
      • bool(true)
      • If you want to get type of a variable, then use gettype().
      • echo gettype($bool); // prints out &quot;boolean“
      • echo gettype($str);  // prints out &quot;string“
      • To check type of veriables in condition, separate functions are there for each type.
      • basic syntax is is_type(variable)
      • some of it are
      • is_integer
      • is_float
      • is_numeric
      • is_string
      • is_scalar
      • is_object
      • is_array
      • It returns true if variable will be of that specific type. Otherwise it returns false.
      • 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.
      • settype($var, &quot;integer&quot;);
      • In php, default error reporting setting allows you to use unassigned variables without errors.
      • To change this setting you should set error reporting level to E_ALL in your php.ini file.
      • error_reporting(E_ALL);
      • To check if variable is assigned a value or not, use isset($var) .
      • PHP variables are global in scope. You can use it throughout your program.
      • To define boolean variable,
      • $flag=True;
      • To define string variable,
      • $str=“string variable”;
      • String can be enclosed in double quotes, single quotes or you can also use heredoc operator.
      • $str = <<<EOF Example of string spanning multiple lines using heredoc syntax. EOF;
      • To define constant,
      • define(&quot;MAXSIZE&quot;, 100);
    • Operators
      • Arithmetic : +,-,/,%,*
      • String . , .=
      • Assignment operators for all above operators. +=, -= etc , ++ , --
      • Comparision
      • == , != , <> , > , >= , < , <= , ===
      • === returns true if its two operands are having the same value, and they are of the same type.
      • e.g.
      • $a=15;
      • $b=15;
      • if( $a === $b)
      • {
      • print “Identical variables”;
      • }
      • PHP supports one execution operator: backquotes (``).
      • PHP will attempt to execute the contents of the backquotes as a system command; the output will be returned in a variable.
      • <?php $output = `ls`; echo &quot;<pre>$output</pre>&quot;;
      • ?>
    • Control Structures
      • if,else,elseif
      • while,for , do..while , for , foreach , break , continue , switch
      • $i=1;
      • 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;; }
      • comments .
      • # , // , /* */