Menu Bar

Introduction to PHP

PHP: Hypertext Preprocessor.
  • PHP is  a widely used, open source scripting language.
  • PHP files can contain text, HTML, CSS, JavaScript and PHP code.
  • PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.
  • It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix and Microsoft SQL Server.

To Start PHP: Install a web server, and then install PHP and MySQL

Uses:
  • PHP performs system functions, i.e. from files on a system it can create, open, read, write and close them.
  • PHP can handle forms, i.e. gather data from files, save data to a file, through email data can be sent, return data to the user.
  • Add, delete, modify elements within the database through PHP.
  • Access cookies variables and set cookies.
  • Using PHP user restriction is possible to access some pages of the website.
  • It can encrypt data.

Characteristics:
  • simplicity
  • efficiency
  • security
  • flexibility
  • familiarity
Basic PHP syntax: A PHP script starts with <?php and ends with ?>
                                The default file extension for PHP files is .php

Simple Hello world program:



Comments in PHP:

// - Single line comment
# - Single line comment
/*.........
  .........
*/ - Multiple lines comment block


Variable: In PHP, a variable starts with the $ sign, followed by the name of the variable.

Ex: <?php
       $ text="Hello World!";
       $ x=5;
       $ y=10;
       echo $text;
       echo $x;
       echo $y;
       ?>


Rules for PHP variables:

  • A variable starts with the $ sign, followed by the name of the variable.
  • A variable name must start with a letter or the underscore character.
  • A variable name cannot start with a number.
  • A variable name can only contain alpha numeric characters and underscores.
  • Variable names are case sensitive.