PHP NOTES

Shared by: engineerranveer
Categories
Tags
-
Stats
views:
7
posted:
1/27/2013
language:
pages:
22
Document Sample
scope of work template
							                                 PHP NOTES

INSTALL IIS

    IIS is Internet Information Services.
    IIS is windows created web server.
    IIS is a windows component.


INSTALLATION PROCESS OF IIS

    Start > setting > control panel > add or remove programs > select
     add or remove windows component.
     (If there is IIS not selected than do it)
    Select IIS from list.
    Next
    Finish > Insert windows xp cd.


The default server directory of IIS is “wwwroot” present in c:\Inetpub
folder. That means all server side applications has to be placed in
“wwwroot” folder.

The default port of IIS is 80.

A simple HTML program:

<html>

<body bgcolor=green text=white>

<h1>wallcome to peers tech.</h1>

</body>
</html>

Save the above program as “One.html” in c:\Inetpub\wwwroot folder.

Client invokes the above program using the browser and the URL as:
http://<name of server>:port/One.html

Or

http://localhost/One.html

PHP Program

<?php

Echo “<h1>Response from One.php</h1>”

?>

Save the above program as One.php in c:\Inetpub\wwwroot

Client invokes the above application using the URL
http://localhost/One.php

To execute any program in the web server corresponding handlers
(executable file) are required in the web server.

PHP Handlers (executable) is php5isapi.dll

Isapi stands for Internet Server Application Programming Interface

For Downloading :

Download PHP and configure IIS with PHP handler.

Download PHP from:

www.php.net/downloads.php
Download software and extract in c:\PHP.

The handler for PHP (php5isapi.dll) will be present in c:\PHP folder.

Open IIS control panel:

Start > run > inetmgr

Or

Start > setting > control panel > administrative tools > IIS

Expand local computer

Expand website

Right click on “Default Website” properties [Default website properties
dialog box will be open]

Select “Home directory” tab

Click on “configurations” button

Click on “Add” button
To develop a display a PHP project we require the following:

   1.   PHP software
   2.   Data base server
   3.   Web server
   4.   FTP client for uploading and downloading files
   5.   Mail server
   6.   A tool for remote DBA


The installer used to install all the above are:

WAMP: Windows Apache MySQL PHP

LAMP: Linux Apache MySQL PHP

MAMP: Macintosh Apache MySQL PHP

XAMP: Crossplatform Apache MySQL PHP PERL
                              20/05/2010

Download and Install XAMPP:

Open google and search for XAMPP for windows download

apache_groups.org

xampp-win32-1.7.3.exe

xampp installs:

  1.   PHP
  2.   PERL
  3.   MySQL DB Server
  4.   Apache web server
  5.   FileZilla-FTP client
  6.   Mercury-mail server
  7.   Phpmyadmin is a tool developed in PHP language for remote DBA.


In the case of Apache web server of XAMPP, all the server side
application should be placed in “htdocs” folder in c:\xampp.

The default port of Apache web server is 80.

To start Apache web server.

  1. Open XAMPP control panel
  2. Click in start button of Apache
  3. Click on “port check” button in XAMPP control panel to check the
     free and used port numbers.

  After starting the web server.
  Open browser and provide the URL as http://localhost

  Open notepad:

  <?php

  echo “<h1>Response from Apache server</h1>”

  ?>

  Save the above program as One.php in c:\xampp\ntdocs

  Client can invoke the above program by using the URL:

  http://localhost/One.php

  Q: How to change the port of Apache web server from 80 to 8082?

  Ans:

       1. Open “http.conf” file from c:\xampp\apache\conf directory
       2. Search for “Listen 80” and replace 80 with 8082
       3. Search for “Servername Localhost : 80” and replace 80 with
          8082
       4. Save the file and restart Apache web server

Now Apache works in the port 8082.

To invokes One.php we can use the URL http://localhost:8082/One.php

A PHP project contains different types of files like:

  1.   HTML
  2.   Cascading style sheets
  3.   Java scripts
  4.   XML
  5. XSL-XML style sheet language files
  6. PHP files
  7. PHP classes
  8. PHP interface
  9. A normal file
  10.     Sub directories …etc...

The different IDEs uses for developing a PHP project are:

  1.   Zend Studio
  2.   Rapid PHP
  3.   PHP Designer
  4.   PHP Edit
  5.   PHP Ed
  6.   CodeLobster
  7.   Dreamvieser
  8.   Netbeans IDE for PHP ...etc…

Download and Install Netbeans IDE for PHP:

   www.netbeans.org/downloads
   Netbeans-6.8-ml-php-windows.exe

The prerequisite for the installation of Netbeans IDE for PHP is,
Java(jdk1.6) should be present in your system.

Create a project with the name PHPProj20 using netbeans IDE.

  1. Open Netbeans IDE
  2. File > New Project > select “PHP” from categories and “PHP
     Application” from projects.
  3. Next
  4.   Project name: PHPProj20
  5.   Next
  6.   Run as: local website
  7.   URL: http://localhost:8082/PHPProj20/
  8.   Finish

As a result of the above steps a new directory with the project name
[PHPProj20] gets created in c:\xampp\htdocs folder.

21/05/10

  9. Integrate a PHP file with the PHPProj20.
  10.     Right click on the project node > New > PHP File




  Program:>
<?php

Echo “<h1>Response from PHPProj20</h1>”

?>

Start Apache Server

To invoke One.php http://localhost:8082/PHPProj20/One.php

Or

Select One.php > Right click > Run

Or

Select One.php > Shift+F6



Basic PHP syntax :>

      In a PHP program server side PHP scripts are integrated in side
       a markup language HTML.
      In a PHP program PHP scripts should be written inside a PHP
       block.
      A PHP clock can be placed any where in the program and it can
       be present any number of types.
      A standard PHP block start with <?php and end with ?>
      An server with shorthand support enable we can use short
       open block with <? And ends with ?> and also in ASP style block
       start with <% and ends with %>.
      Shorthand open block and ASP style block will be allowed by a
       web server only if it is configured in php.ini.
 php.ini is present in c:\xampp\php folder.
 Search for the value of “short_open_tag” and “asp_tags” in
  php.ini file to identify whether the web sever supports short
  open block or ASP block.
 echo and print are the two language construct of PHP used for
  outputting text or to give a response back for the client.
 Semicolon is used to distinguish multiple PHP scripts.

Comment in PHP:>

In PHP we use // or # to make a single line comment or /* and */
to make a comment block.

Program :>

<html>

<body bgcolor="pink">

<?php

echo "<h1 align=center>PEERS TECHNOLOGY</h1>";

print "<h3 align=center> 207, HUDA, MAITRIVANAM AMEERPET
</h3>"

?>

<hr color="red" size="s">

<?PHP

echo "<h2>Hi friends</h2>"

?>
</html>

Variables in PHP :>

   Variable are used for storing values like text strings, number,
    array.
   When a variable is set it can be used over and over again in
    your script.
   All variable in PHP start with a “$” sign symbol.
   In PHP a variable does not used to be declared before being
    set.
   You do not have to tell PHP which data type the variable is.
   In PHP the type variable is automatically indentified based as
    who it is set.
   In any programming language variable are of type.
             a. Value types
                int a=10;
                int b=a;
                b=20;
             b. Reference types
                Employer emp1 = new employee ();
                 Employer emp2 = emp1;
      PHP automatically convert the variable to the correct data type
       depending on how they are set.

     Variable naming rule :>

1.   A variable name can have alphanumeric character or underscore.
2.   A variable name should start with a latter or underscore.
3.   No space is allow between the character in a variable name.
4.   It is advisable not to use the reserved keyword to PHP.
     Example :>

$firstName

$last_name

$_age

Dot (.) is concatenation operator of PHP used for concatenating
different type of data. For concatenating we used comma (,) also.

<?php

$firstName = "peers";
$last_name = "tech";

$_age = 13;

echo $firstName. $last_name. $_age

?>

     24/05/10

PHP DATA TYPES

PHP supports eight types of data.

     1. Four Scalar Types.

[A variable in which only one value can be stored at a time]

          i. boolean
         ii. integer
        iii. float/double
     2. Two Compound Types.

A variable in which multiple values can be stored at a time.

          i. Array
         ii. object
     3. Two Special Types.
          i. resource
         ii. NULL

The type of a variable is usually not set by the programmer; rather it is
decided at runtime by PHP depending on the context in which that
variable is used.
var_dump (variable_name) is a built-in function of PHP used for getting
the type of the variable with content as the variable.

Example:

<?php

echo "<h1>";

$x=10;

var_dump($x);

echo "<br>";

$x=10.65;

var_dump($x);

echo "<br>";

$x="peers";

var_dump($x);

echo "<br>";

$x=true;

var_dump($x);

echo "<br>";

?>

gettype (variable_name) is a function of PHP used for getting the type
of the variable.
settype (variable_name, new type) is a function of PHP used for setting
a new type to the variable.

unset (variable_name) is a function of PHP used for removing the
content of a variable.

Example:

<?php

echo "<h1>";

$x=10;

echo gettype($x). "<br><br>";

$x=10.65;

echo gettype($x). "<br><br>";

$x="A10A";

var_dump($x);

echo "<br>";

settype($x, "integer");

$x=10;

var_dump($x);

echo "<br>".gettype($x);

?>

“is_[type] (variable name)” set of function including is_int(),
is_double(), is_float(), is_bool(), is_string(), is_array(), is_integer,
is_object(), etc to check whether a specific variable matches the data
type.

Example:

<?php

echo "<h1>";

$x="10";

if (is_int($x))

  echo "Variable is of Integer type";

else

  echo "Variable is NOT of Integer type"

?>

Constant variable in PHP:

A variable whose value can not be changed or a variable that can not be
assigned is known as a constant variable. In PHP constant are created
using the define function.

Example:

Define (string constantName, value);

A constant variable name should not start with $ sign. Normally
constant are declared with the capital latter.

In PHP all the variable names are case sensitive.
PHP_OS is a predefined constant if PHP used for getting the name of
the operating system in which current PHP installation is done.

phpinfo() is a built-in function of PHP used for getting the complete
system configuration details related to PHP.

Example:

<?php

echo "<h1>";

define("NAME","Peers Tech");

define("AGE",20);

echo NAME."__".AGE. "<br>";

echo PHP_OS. "<br>";

phpinfo();

?>

Operators in PHP:

Operators are used to perform a particular operation and operators are
broadly classified into two categories.

      Unary operator

     Operators that are require only one operand.

     Example: $a++

      Binary operator

     Operators that are require two operands.
    Example: $x+$y

    Example:

    <?php

    echo "<h1>";

    $a="peers";

    $b="tech";

    $c=$a+$b;

    echo"Sum=". $c."<br>";

    $res=-10%-3;

    echo$res;

    ?>

2. Relation operator:

<   > <= >= == != <>           === !==

== will check only for the contents where.

=== will check for content and also for the type.

Example

    <?php

    $x=10;

    $y=10;

    if($x=$y)//($x===$y)
echo “both are equal”;

else

echo “both are not equal”;

?>

  3. Logical operator

  && (AND)

  || (OR)

  ! (NOT)

  Logical operators are used to make a compound condition.

  In the case of logical operator both the expression will not be
  evaluate the every time.

  4. Assignment operator

  =       +=    -=   *=   /=   %=

  [$a+=$b=>$a=$a+$b]

     5. Increment/Decrement operator

     ++    --

     Example

     $a=10;

     Echo $a++;

  6.      Negation operator
$a=10;

$b=$-a;

7.   Bitwise operator

$ (Bitwise AND)

! (Bitwise OR)

^ (Bitwise XOR)

Example:

$a=10;                       10 -> 1010

$b=15;                        15 ->   1111

$x=$a & $b;                           1010    (10)

$y=$a||$;                             1111    (15)

$z=$a^$b;                             0101    (5)

echo $x.”__”.$y.”__”.$z;

      10         15     5

In the case of bitwise operator both the operands will be
connected to binary form and corresponding bitwise operation will
be performed.

8. Shift operator

<< -> Left shift

>> -> Right shift
In case of shift operators the first operand will be converted to
binary form and corresponding shift operators will be performed.

Example:

<?php

echo "<h1>";

echo (100<<4)."<br>";

echo (100>>3);

?>

     9. concatenation operator

 .     .=

 Example:

 <?php

 echo"<h1>";

 $a=10;

 $b=5;

 $res=$a/$b;

 echo"Result=".$res."<br>";

 echo"Applocation over";

 ?>

10.

						
Related docs
Other docs by engineerranveer
PHP NOTES
Views: 7  |  Downloads: 0
MY SQL
Views: 8  |  Downloads: 0