PHP also having operators like other programming Languages like Java, C++, and C etc.
PHP operators are:-
- Assignment Operators.
- Arithmetic’s Operators.
- Comparison Operators.
- String Operators.
Assignment Operators:
PHP having assignment operators i.e. (=)
Example:
Arithmetic’s Operators:
PHP Arithmetic’s Operators are: +,-,*,/,%.
Example:
Comparison Operators:
Example:
String Operators:
PHP Strings Operators are:
There are generally tow String Operators in PHP
- First is a concatenation Operators (‘.’).
- The Second one is Assignment Operators (‘=’)
Example:
PHP Conditional Statements
PHP Conditional operators are:
- IF Statement.
- IF..ElSE Statement.
- IF..ELSEIF….Statement
- Switch Statement.
IF Statement: Like other programming language IF statement executes some statement when some particular condition is true.
Syntax: If (condition)
Code Execute;
Example:
IF..Else Statement: IF statement is true then execute one statement otherwise execute second statement.
Syntax:
Example:
IF..ELSEIF….Statement : If some condition is true then execute one statement else if some another statement then execute another statement. It is particularly an if else ladder.
Syntax:
Example:
Switch Statement: To overcome the multiple If-Else statement problems we used switch statement. It is conditional statement are used to perform different action based on different conditions.
Working of Switch Statement: It takes one variable as input and checks it against all the different cases you set for the switch statements.
Syntax:
What is PHP?
Php stands for pre hypertext programming language or hypertext preprocessor. It is a server site programming language like other programming language like Asp.net etc.
Now a day it is very much popular in website development. Many big websites like yahoo, Facebook and many other social networking sites are generally made in php .
Php files have a file extension .php, .php3 , .phtml etc.
Features of PHP
There are many features of php:
- It is server site programming language.
- Php is an open source language and it can be free download and use .
- It is a loosely type language there is no need to declare the type of variable in php.
Database in PHP
Php support many databases like MySQL, Informix, Oracel, ODBC etc. Rather than it is also having its database i.e. phpMyAdmin.
Basic Body Architecture of PHP
Statement;
Statement;
?>
The whole programmed in php is written in between .
Evolution of PHP
Php was developed by Ramus Lerdrof in 1994. After that it was modified by Zeev Suraski and Andi Gutmans in 1997.
After installation php in your computer you can test your browser by typing:
http://localhost and then press enter
Variables in PHP
Variables are used to store information or a value to its. Like other programming language php have its own variable .but in php there is no need to define its data type it will be automatically regret its vale that it is of integer or character type.
In php variable define with a sigh of ‘$’ i.e.
$a, $abc etc.
The first character after $ must be character or underscore. The remaining character in name may be letter , number or underscore.
Syntax :
$variable_name = value;
Example:
$a
$a=10;
$b=20;
$c= $a+$b;
First programme in PHP
Echo “Hello”;
php?>
echo: eco is used for output a string and must be ended with a semicolon. The string must be written in between doubleqoutes.
We can also use print as in place of echo.
Example:
Print “Hello My Name is Pankaj Singh”;
?>
Output: Hello My Name is Pankaj Singh
Example:
$abc=” Hello My Name is Pankaj Singh”;
Echo $abc;
Print $abc;
?>
Output of above program is:
Hello My Name is Pankaj Singh Hello My Name is Pankaj Singh
Comment in PHP
There are generally two types of comments used in php
- Single line comments : //
- Multiline comment: /*….*/
Example:
// this is a single line comment
?>
/* This
Is a
Multiline comment
*/
?>
Introduction to PHP
PHP stands for Hypertext Preprocessor.It is a server-side scripting language.It is an open source software and free to download and use.
PHP files have a file extension of ".php", ".php3", or ".phtml".
PHP script:
PHP scripting block always starts with
Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.
variables :
All variables will start with $ symbol.
Simple example
$var_name = value;
condition statement:
All the condition statement syntax are same as in C language.Example if..else,switch.
Array:
Array is a homogenious collection of elements.
$arr[0]="12345";
echo $arr[0];
There are 3 types of arrays
1)Numerical arrays
2)Associative array
3)Multi dimensional arrays
Numerical arrays:
A numeric array stores each array element with a numeric index.
$type=array("cat","dog","rat");
Internally it will store as
$type[0]="cat";
$type[1]="dog";
$type[2]="rat";
Example
$type[0]="cat";
$type[1]="dog";
$type[2]="rat";
echo $type[0] . " kills " . $type[2];
?>
Associative array:
In associative array the index is replaced with a value.
$names = array("ravi"=>40, "rani"=>45, "ram"=>50);
$names['ravi']="40";
$names['rani']="45";
$names['ram']="50";
example:
$names['ravi']="40";
$names['rani']="45";
$names['ram']="50";
echo "marks of ravi,rani,ram are". $names['ravi'] .$names['rani']. $names['ram'];
?>
Loops:
All the loop statement syntax also similar as in C language.
example:
WHILE
while (condition)
{
code to be executed;
}
example:
$temp=0;
while($temp<=10)
{
echo "The number is" . $temp ;
$temp++;
}
?>
DO-WHILE
do
{
code to be executed;
}
while (condition);
example:
$temp=0;
do
{
echo "The number is" . $temp ;
$temp++;
}while($temp<=10)
?>
FOR
for (init; condition; increment)
{
code to be executed;
}
example:
for($temp=0;$temp<=10;$temp++;)
{
echo "The number is" . $temp ;
}
?>
Mantis bug tracker is free web based bug tracking system.
This software needs php,apche server or iis and mysql.
This software code was written in php.
To run this sofware we should have basic knowledge in php, server and mysql.
You can see all information in the following website. http://www.mantisbt.org/
A Very first version of php is PHP/F1 at 1995 its called Personal Home Page Tools' set of script ,next version of php 2.0 was released at 1997 somewhat more future and several peoples used it, after very short period they released PHP 3(1998) ,Its new version with more function so its called differently compare to PHP2.0 that is recursive acronym – PHP: Hypertext Preprocessor.
After small interval they released PHP4 in 1999 with wide range of additional new features and more no of developers PHP 5 was released in July 2004 after long development PHP is open source general-purpose scripting language with embed In HTML coding ,Its used to develop a dynamic WebPages with added new API packages
Example
First Application
echo "Hi, First PHP script Example. . . . ";
?>
In PHP Scripting Start’s and End’s with
Variable Declaration
In PHP Variables are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive
Example
$Val=’String’;
$Val1=24;
?>
Here variable $val,$val1
Global Variable Declaration
In PHP Global Variable Different from other language, if u can access global variable means you must declare with in the function only
Example
$value=’one’;
function Fn_test()
{
global $value;
$value=’Two’;
}
Fn_test();
echo $value;
?>
Here output is Two only ,because in function Fn_test take the global value Two only
Mysql Database Connection in sample coding For PHP
$host=”Localhost”;
$user=”test”;
$pass=”Invdb”;
/* Connecting, selecting database */
$Conn = mysql_connect($host, $user, $pass)
or die("Could not connect");
mysql_select_db("DatabaseName") or die("Check your Database");
/* SQL Operation Here Select, Insert and others */
/* Closing connection */
mysql_close($Conn);
?>