MCR Web Solutions
Home HTML CSS JavaScript PHP MySQL AJAX Model Questions Resources

PHP: PHP Hypertext Preprocessor

PHP is a server-side scripting language where the code is executed in the server. Other server-side programming languages include ASP, JSP etc.


UNIT V CONTENTS

PHP Introduction, Creating PHP Script, Running PHP Script, Variables & Constants, Data types, Operators.


UNIT VI CONTENTS

PHP Conditional Statements & Control Statements, Arrays, Functions, Working with forms and database using MySQL.


PHP Introduction

  • PHP stands for PHP: Hypertext Preprocessor.
  • It is a server side scripting language like ASP, JSP and the scripts run in the server.
  • PHP is an open source software and is free to download and use.
  • It is compatible with many databases such as MySQL, Oracle, Sybase, and other popular DBMS.
  • PHP runs on all platforms (Linux, Windows etc) and is compatible with almost all servers used today (Apache, IIS, etc).
  • It is easy to learn and runs really efficient on the server side.
  • PHP code can be embedded in the HTML code like javascript.
  • Extension of PHP files can be .php, .php3 or .phtml

Top


Creating & Running PHP Script

  • PHP is a server-side scripting language. So, to run PHP scripts, you need to install PHP and a web-server software like Apache. For scripting using databases, a DBMS such as MySQL should be installed.
  • The most compatible options include PHP + Apache + MySQL.
  • The PHP files (.php files) should be copied to a particular folder (htdocs or html or www etc.) where the webpages need to be hosted.
  • The basic syntax of a PHP code is as follows:
    <HTML>
    <BODY>

    <?php
    echo "Hello VIT!";
    ?>


    </BODY>
    </HTML>
  • After copying the files to the server, you can type the ip of the system followed by the php page in the URL bar of the browser . For example, http://192.169.1.112/test.php. To access the PHP page in the same system use, http://localhost/test.php
  • Each statement in PHP ends with a semicolon (;).
  • To output text or result to the screen in PHP, echo or print can be used. Example, print "Hello";
  • Comments in PHP is similar to that of Javascript. For single line, // can be used. For multiline comments, /* and */ can be used.

Top


PHP Variables & Constants

  • PHP variables start with $. For example, $name = "Suresh Mudunuri", $i=55 etc.
  • More Information on PHP Variables can be found @
    • http://www.tizag.com/phpT/variable.php
    • http://www.w3schools.com/php/php_variables.asp
  • Constants are variables whose values can not be changed. Constants in PHP can be created using the define statement. Example, define(PI, 3.14); echo PI; - This statement will print 3.14

Top


PHP Data Types

  • PHP supports data types that are similar to JavaScript. But, broadly they can be categorized to 3 types - Numeric, String and Array.
  • Numeric: PHP variables can hold data of all types of numbers like integers, floating point values etc.
  • Strings: Strings are used for holding characters and text.
  • Arrays: Arrays store multiple values in a single varaible. PHP Arrays are of 3 types - Numeric, Associative (ID, Key pairs) and Multi-Dimensional Arrays.
  • Information about the PHP data types can be found @
    • Strings: http://www.w3schools.com/php/php_string.asp
    • Built-in Functions of PHP Strings: http://www.w3schools.com/php/php_ref_string.asp
    • Arrays: http://www.w3schools.com/php/php_arrays.asp
    • Built-in Functions of PHP Arrays: http://www.w3schools.com/php/php_ref_array.asp

Top


PHP OPERATORS

  • PHP supports The following operators:
    • Arithmetic (+, -, *, /, %, .)
    • Assignment (=, +=, *=, .=, etc.,)
    • Increment/Decrement (++, --)
    • Relational (==, >, <, <=, >=, !=) Special:===, !==, <> (Not equal to)
    • Logical (&&, ||, !) Alternates:and (&&), or (||)
    • Array Operators: + (union), == (equality), === (identity), != / <>(inequality), !== (non-identity)
  • More information about PHP operators can be found @
    • Operators: http://www.w3schools.com/php/php_operators.asp

Top


PHP Conditional & Control Statements

  • PHP supports The following conditional statements:
    • If statement
    • If-else statement
    • If-elseif-else statement
    • Switch statement
    • While Loop
    • Do-While Loop
    • For Loop
    • For-Each Loop
  • Information about the usage of PHP Coniditonal Statements can be found @
    • If-esle statements: http://www.w3schools.com/php/php_if_else.asp
    • Switch statement: http://www.w3schools.com/php/php_switch.asp
    • While & Do-while Loops: http://www.w3schools.com/php/php_looping.asp
    • For & For-each Loops: http://www.w3schools.com/php/php_looping_for.asp

Top


PHP Functions

  • Functions are the real power for PHP. There are as many as 700 built in functions in PHP.
  • You may call a function from anywhere within a page.
  • Usage of PHP functions with arguments and return statements ia almost similar to that of javascript functions.
  • The basic syntax of a PHP code is as follows:
    <?php

    function add()
    {
    echo "Hello VIT!";
    }

    add();//function call
    ?>


  • Information about PHP functions can be found @
    • PHP Functions: http://www.w3schools.com/php/php_functions.asp
    • PHP Functions Reference: http://www.w3schools.com/php/default.asp

Top

© MCR Web Solutions, Bhimavaram.