PHP Tutorial


PHP is a server side scripting language. It means that the script runs on your web server, not on the user’s browser. With the help of PHP you can collect form data, generate dynamic pages, create username and password login pages, picture galleries, surveys, send and receive cookies with the help of PHP. This is nothing at all you can do much more using PHP codes. Normally if you ask from any one then he will tell you that PHP is used for making dynamic and interactive Web pages.

All the major Operating Systems like Linux, Unix, Microsoft Windows, Mac OS and probably some others supports PHP. Now a day’s PHP also supports a wide variety of web servers like Apache, IIS etc. PHP is able to work either as a module or as CGI processor. With PHP you have a choice of using a programming language either Procedural or Objected Oriented (OOP) or you can use both. PHP also facilitates the output as images, PDF files and Flash moves also. PHP also has useful text processing features, which includes the Perl compatible regular expressions (PCRE).

PHP also supports a wide range of Databases. You can create a web page and you can connect it to database and after entering any query it will collect the data from the database and provides you the answer. PHP also support other services those are using protocols like LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM.

Initially some people call PHP as Personal Home Page and after that some people call it as Hypertext Pre-Processor. It is open source and easy to use. People those are familiar with C and C++ can easily code a web page in PHP.

PHP facilitates to use your old code with new versions of PHP by adding some changes. Now a day’s based on the performance and features PHP is the most popular scripting language on the web. PHP is very popular just because if you want to learn this language you can only take help from some tutorials and little bit guidance. There is a very bright future in the web designing and development of websites.

There are three main areas where PHP scripts are used

  • Server-side scripting
  • Command line scripting
  • Writing desktop applications

Functions of PHP:

  • Calendar functions
  • Error functions
  • Mail functions
  • SimpleXML functions
  • String functions
  • Math functions
  • Misc functions
  • HTTP functions
  • XML Parser functions
  • Filter functions
  • FTP functions
  • Array functions
  • Date functions

PHP Variables

  1. Strictly starts with a $ sign.
  2. Cannot start with a number
  3. Variables are case-sensitive

Scope of PHP Variables

  1. local
  2. global
  3. static

User Defined Functions in PHP

User can create their own functions and call them to the function. You can call a function multiple times. The declaration of user defined function always starts with word “function”.


function functionName() {

   code to be executed;


Constants in PHP

A constant is a value that can’t be changed or undefined during the script.


define(name, value, case-insensitive)

Operators in PHP

  • Assignment operators
    • x = y x += y
    • x -= y
    • x *= y
    • x /= y
    • x %= y
  • Arithmetic operators
    • Addition
    • Subtraction
    • Multiplication
    • Division
    • Modulus
    • Exponentiation
  • Array operators
    • +
    • ==
    • ===
    • !=
    • <>
    • !==
  • Logical operators
    • and
    • or
    • xor
    • &&
    • ||
    • !
  • String operators
    • .
    • .=
  • Comparison operators
    • ==
    • ===
    • !=
    • <> !==
    • >
    • <
    • >=
    • <=
  • Increment/Decrement operators
    • ++$x (Pre-increment)
    • $x++ (Post-increment)
    • –$x (Pre-decrement)
    • $x–     (Post-decrement)

Conditional Statements in PHP

  • If statement
  • If – else statement
  • If – elseif else statement
  • Switch statement

Data Types in PHP

Variables are used to store data of different types. In PHP there are different Data Types.

  • String – A string is a sequence of characters, like “Hello John!”
  • Integer – It have at least one digit (i.e. 0 – 9).
  • Float (floating point numbers – also called double) – Numbers with decimal point or with exponential form.
  • Boolean – It represents two states either TRUE or FALSE.
  • Array – It have the capability to store multiple values in one variable.
  • Object – It is a data type which stores data.
  • NULL – It has only one value: NULL
  • Resource – It is not actually a data type it is basically storing of a reference to functions.

String Functions

  1. Length of a string (number of characters) – strlen()
  2. Number of words in a string – str_word_count()
  3. Reverses a string – strrev()
  4. Search for a specific text within a string – strpos()
  5. Replace some characters with some other characters in a string – str_replace()

How to start with PHP?

You don’t need to start with software to write a php code, a text editor like Notepad is sufficient for startup.

How to declaring PHP codes?

PHP scripts always written in between two PHP tags.

1. <?

Hello PHP


2. <?php

Hello PHP


3. <script language=”php”>

Hello PHP


Write you first script: hello.php



<title>PHP Test</title>



<?php echo ‘<p>Hello World</p>’; ?>



Forms in PHP

One of the most important feature of PHP is it handles the HTML forms. You can also add your HTML forms in PHP script easily. Let’s have an example:

<form action=”action.php” method=”post”>

<p>Your name: <input type=”text” name=”name” /></p>

<p>Your age: <input type=”text” name=”age” /></p>

<p><input type=”submit” /></p>


IF Statements

IF is used as a decision statement and to compare two values. ELSE statement is used with IF statement.

IF (something == something else)


THEN Statement




ELSE Statement


Now make the proper use of ELSE Statement

 if ($username == “John”) {

echo “Successful”;

} else {

echo “failed”;


The WHILE Loop

It helps to execute a code in a loop until certain condition occurs.

 $command = 10;

$x = 0;

while ($x < $command) {

echo “Hello World”;




Set up an array with 5 names in it:

 $names[0] = ‘Rohan’;

$names[1] = ‘Rahul’;

$names[2] = ‘Amit’;

$names[3] = ‘Rani’;

$names[4] = ‘Raj’;

Now if I want to print out the third name.

echo “The third name is $names[2]”;

 Which would output: The third name is Amit.

For More check SEO Tutorials




InRaMS technologies is a web based company here we have Digital marketing, web development. In digital marketing we have Small SEO tools and also Try this Website SEO Audit Tool

Leave a Reply

Your email address will not be published. Required fields are marked *

8 + fourteen =

Time limit is exhausted. Please reload CAPTCHA.