SlideShare a Scribd company logo
PAPER NAME : PROGRAMMING IN PHP
STAFF NAME : MS. V. SHANTHI M.sc, M.phil,M.tech,PGDAS.
CLASS : III BCA-A
SEMESTER : VI
PHP is a recursive contraction for "PHP: Hypertext
Preprocessor".
PHP is a server side scripting language that is
implanted in HTML. It is used to accomplish dynamic
content, databases, session tracking, even build entire
e-commerce sites.
It is cohesive with a number of prevalent databases,
counting MySQL, Postgre SQL, Oracle, Sybase, Informix,
and Microsoft SQL Server.
PHP is satisfyingly active in its carrying out, exclusively
when pile up as an Apache building block on the Unix
side.
The MySQL server, once in progress , achieves equal
precise composite queries with giant consequence sets in
record-setting time.
PHP provisions a enormous number of main rules such
as POP3, IMAP, and LDAP. PHP4 added provision for
Java and dispersed entity planning (COM and CORBA),
making n-tier improvement a option for the first time.
PHP is tolerant: PHP language tries to be as tolerant as
possible.
PHP Syntax is C-Like.
PHP implements method functions, i.e. from records
on a system it can create, open, read, write, and close
them.
PHP can grip forms, i.e. fold data from files, save data
to a file, through email you can send data,
reoccurrence data to the user.
You add, delete, modify features within your
database through PHP.
Access cookies variables and set cookies.
Using PHP, you can curb users to access some pages
of your website.
It can scramble data.
Five important characteristics make PHP's practical
nature possible −
Simplicity
Efficiency
Security
Flexibility
Familiarity
To get a feel for PHP, first start with modest PHP
scripts. Since "Hello, World!" is an important example, first
we will create a friendly little "Hello, World!" script.
<html>
<head>
<title>Hello World</title>
</head>
<body>
<?php
echo "Hello, World!";
?>
</body>
</html>
It will produce following result − Hello, World!
In order to cultivate and run PHP Web pages three
vital components need to be installed on your computer
system.
Web Server − PHP will work with practically all Web
Server software, including Microsoft's Internet
Information Server (IIS) but then most often used is freely
available Apache Server.
Download Apache for free here −
https://httpd.apache.org/download.cgi
Database − PHP will work with practically all database
software, including Oracle and Sybase but most
commonly used is spontaneously accessible MySQL
database.
Transfer MySQL for free here −
PHP Parser − In order to practice PHP script guidelines a
parser must be connected to generate HTML output that
can be sent to the Web Browser. This lecture will guide
you how to connect PHP parser on your computer.
https://www.mysql.com/downloads/
Before you ensue it is important to make sure that you
have accurate environment setup on your machine to
develop your web programs using PHP.
Type the following reportinto your browser's
address box.
http://127.0.0.1/info.php
If this displays a page displaying your PHP
connection related information then it means you have
PHP and Webserver installed properly.
Otherwise you have to follow given method to install
PHP on your computer.
This section will guide you to install and design PHP over
the following four platforms −
PHP Installation on Linux or Unix with Apache
PHP Installation on Mac OS X with Apache
PHP Installation on Windows NT/2000/XP with IIS
PHP Installation on Windows NT/2000/XP with Apache
If you are using Apache as a Web Server then this
fragment will guide you to edit Apache Configuration
Files.
Just Check it here −
The PHP configuration file, php.ini, is the final and
most instantaneous way to affect PHP's functionality.
PHP Configuration in Apache Server
Just Check it here −
To design IIS on your Windows machine you can
refer your IIS Position Guide shipped beside with IIS.
PHP.INI File Configuration
The main way to collection information in the
intermediate of a PHP program is by using a variable.
Here are the most imperative possessions to know
about variables in PHP.
All variables in PHP are signified with a leading dollar
sign ($).
The value of a variable is the value of its most current
assignment.
Variables are assigned with the = operator, with the
variable on the left-hand side and the expression to be
estimated on the right.
Variables can, but do not need, to be confirmed before
assignment.
Variables in PHP do not have inherent types - a variable
does not know in improvement whether it will be used to
store a number or a string of characters.
Variables used before they are dispensed have default
values.
PHP does a good job of spontaneously exchanging types
from one to another when necessary.
PHP variables are Perl-like.
PHP has a total of eight data types which we use to
construct our variables −
Integers − are whole numbers, without a decimal
point, like 4195.
Doubles − are floating-point numbers, like 3.14159 or
49.1.
Booleans − have only two possible values either true or
false.
NULL − is a special type that only has one value: NULL.
Strings − are sequences of characters, like 'PHP
supports string operations.'
Arrays − are named and indexed collections of other
values.
Objects − are occurrences of programmer-defined
classes, which can package up both other kinds of
values and functions that are particular to the class.
Resources − are special variables that hold locations
to resources external to PHP (such as database
connections).
The first five are simple types, and the next two
(arrays and objects) are compound - the compound
types can package up other arbitrary values of
arbitrary type, whereas the simple types cannot.
Simple answer can be given using expression 4 + 5 is
equal to 9. Here 4 and 5 are called operands and + is
called operator.
PHP language supports following type of operators.
Arithmetic Operators
Comparison Operators
Logical (or Relational) Operators
Assignment Operators
Conditional (or ternary) Operators
There are following arithmetic operators supported by
PHP language −
Operator Description Example
+ Adds two operands A + B will give 30
-
Subtracts second operand from the
first
A - B will give -10
* Multiply both operands A * B will give 200
/ Divide numerator by de-numerator B / A will give 2
%
Modulus Operator and remainder of
after an integer division
B % A will give 0
++
Increment operator, increases integer
value by one
A++ will give 11
--
Decrement operator, decreases
integer value by one
A-- will give 9
There are following comparison operators supported by
PHP language
Operato
r
Description Example
==
Checks if the value of two operands are equal or not, if
yes then condition becomes true.
(A == B) is not
true.
!=
Checks if the value of two operands are equal or not, if
values are not equal then condition becomes true.
(A != B) is true.
>
Checks if the value of left operand is greater than the
value of right operand, if yes then condition becomes
true.
(A > B) is not
true.
<
Checks if the value of left operand is less than the
value of right operand, if yes then condition becomes
true.
(A < B) is true.
>=
Checks if the value of left operand is greater than or
equal to the value of right operand, if yes then
condition becomes true.
(A >= B) is not
true.
Checks if the value of left operand is less than or
There are following logical operators supported by
PHP language
Operato
r
Description Example
and
Called Logical AND operator. If both the
operands are true then condition becomes true.
(A and B) is true.
or
Called Logical OR Operator. If any of the two
operands are non zero then condition becomes
true.
(A or B) is true.
&&
Called Logical AND operator. If both the
operands are non zero then condition becomes
true.
(A && B) is true.
||
Called Logical OR Operator. If any of the two
operands are non zero then condition becomes
true.
(A || B) is true.
!
Called Logical NOT Operator. Use to reverses
the logical state of its operand. If a condition is !(A && B) is false.
There are following assignment operators supported by PHP language −
Operato
r
Description Example
=
Simple assignment operator, Assigns values from
right side operands to left side operand
C = A + B will assign
value of A + B into C
+=
Add AND assignment operator, It adds right operand
to the left operand and assign the result to left
operand
C += A is equivalent to
C = C + A
-=
Subtract AND assignment operator, It subtracts right
operand from the left operand and assign the result
to left operand
C -= A is equivalent to
C = C - A
*=
Multiply AND assignment operator, It multiplies right
operand with the left operand and assign the result to
left operand
C *= A is equivalent to
C = C * A
/=
Divide AND assignment operator, It divides left
operand with the right operand and assign the result
to left operand
C /= A is equivalent to
C = C / A
%=
Modulus AND assignment operator, It takes modulus
using two operands and assign the result to left
operand
C %= A is equivalent to
C = C % A
There is one more operator called conditional operator.
This first estimates an expression for a true or false
value and then execute one of the two given statements
depending upon the result of the evaluation. The
conditional operator has this syntax −
Operator Description Example
? :
Conditional
Expression
If Condition is true ?
Then value X :
Otherwise value Y
An array is a data structure that stocks one or more
related type of values in a single value. For example if
you want to collection 100 numbers then instead of
defining 100 variables its easy to define an array of
100 length.
There are three dissimilar kind of arrays and each
array value is retrieved using an ID c which is called
array index.
Numeric array − An array with a numeric index.
Values are stored and retrieved in linear fashion.
Associative array − An array with strings as index. This
stores element values in connotation with key values
rather than in a severe linear index order.
Multidimensional array − An array covering one or
more arrays and values are retrieved using multiple
indices
Numeric array:
 These arrays can store numbers, strings and any object
but their index will be signified by numbers. By default
array index starts from zero.
Example:
Following is the example showing how to create and
access numeric arrays.
Here we have used array() function to create array. This
function is explained in function reference.
<html>
<body>
<?php
/* First method to create array. */
$numbers = array( 1, 2, 3, 4, 5);
foreach( $numbers as $value )
{
echo "Value is $value <br />";
}
/* Second method to create array. */
$numbers[0] = "one";
$numbers[1] = "two";
$numbers[2] = "three";
$numbers[3] = "four";
$numbers[4] = "five";
foreach( $numbers as $value )
{
echo "Value is $value <br />";
}
?>
</body>
</html>
This will produce the following result −
Value is 1
Value is 2
Value is 3
Value is 4
Value is 5
Value is one
Value is two
Value is three
Value is four
Value is five
Associative array −
The associative arrays are very related to numeric
arrays in term of functionality but they are dissimilar in
terms of their index.
 Associative array will have their index as string so that
you can launch a strong suggestion between key and
values.
To pile the salaries of employees in an array, a
numerically indexed array would not be the best choice.
Instead, we could use the employees names as the keys
in our associative array, and the value would be their
separate salary.
NOTE − Don't keep associative array privileged double
quote while printing otherwise it would not return any
value.
Example
<html>
<body>
<?php
/* First method to associate create array. */
$salaries = array("mohammad" => 2000, "qadir" => 1000,
"zara" => 500);
echo "Salary of mohammad is ". $salaries['mohammad'] .
"<br />";
echo "Salary of qadir is ". $salaries['qadir']. "<br />"; echo
"Salary of zara is ". $salaries['zara']. "<br />";
/* Second method to create array. */
$salaries['mohammad'] = "high"; $salaries['qadir'] =
"medium"; $salaries['zara'] = "low";
echo "Salary of mohammad is ". $salaries['mohammad']
. "<br />";
echo "Salary of qadir is ". $salaries['qadir']. "<br />";
echo "Salary of zara is ". $salaries['zara']. "<br />";
?>
</body>
</html>
This will produce the following result −
Salary of mohammad is 2000
Salary of qadir is 1000
Salary of zara is 500
Salary of mohammad is high
Salary of qadir is medium
Salary of zara is low
Multidimensional array −
A multi-dimensional array each component in the main
array can also be an array.
 And each component in the sub-array can be an array,
and so on.
Values in the multi-dimensional array are retrieved
using multiple index.
Example
In this example we create a two dimensional array to
pile marks of three students in three subjects −
This example is an associative array, you can produce
numeric array in the same fashion.
<html>
<body>
<?php
$marks = array( "mohammad" => array ( "physics" => 35,
"maths" => 30, "chemistry" => 39 ), "qadir" => array (
"physics" => 30, "maths" => 32, "chemistry" => 29 ),
"zara" => array ( "physics" => 31, "maths" => 22,
"chemistry" => 39 ) );
/* Accessing multi-dimensional array values */
echo "Marks for mohammad in physics : " ;
echo $marks['mohammad']['physics'] . "<br />";
echo "Marks for qadir in maths : ";
echo $marks['qadir']['maths'] . "<br />";
echo "Marks for zara in chemistry : " ;
echo $marks['zara']['chemistry'] . "<br />";
?>
</body>
</html>
This will produce the following result −
Marks for mohammad in physics : 35
Marks for qadir in maths : 32
Marks for zara in chemistry : 39
for − loops through a block of code a definite number of
times.
Syntax
for (initialization; condition; increment)
{
code to be executed;
}
while − loops through a block of code if and as long as a
quantified condition is true.
Syntax
while (condition)
{
code to be executed;
}
do...while − loops through a block of code once, and then
duplications the loop as long as a distinctive condition is
true.
Syntax
do
{
code to be executed;
}
while (condition);
foreach − loops through a block of code for each
component in an array.
Syntax
foreach (array as value)
{
code to be executed;
}
Continue Statement
The PHP continue keyword is used to halt the recent
iteration of a loop but it does not dismiss the loop.
Just like the break statement the continue statement is
situated privileged the statement block covering the code
that the loop completes, headed by a conditional test.
For the pass meeting continue statement, rest of the loop
code is hopped and next pass starts.
Break Statement
The PHP break keyword is used to dismiss the
execution of a loop prematurely.
The break statement is situated privileged the
statement block.
It gives you occupied control and whenever you
want to exit from the loop you can come out.
 After coming out of a loop instant statement to the
loop will be executed.
If…Else Statement
if...else statement − use this statement if you want to
accomplish a set of code when a condition is true and
another if the condition is not true
Syntax
if (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
ElseIf Statement
Elseif statement − is used with the if...else statement to
implement a set of code if one of the numerous
condition is true
Syntax
if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
Switch Statement
switch statement − is used if you want to select one of
many blocks of code to be implemented, use the Switch
statement.
switch (expression)
{
case label1: code to be executed
if expression = label1;
break;
case label2: code to be executed
if expression = label2;
break;
default: code to be executed if expression is different from
both label1 and label2;
}
Syntax
 There are no simulated limits on string length -
within the restraints of available memory, you ought
to be able to make randomly long strings.
 Strings that are enclosed by double quotes (as in
"this") are preprocessed in both the following two
ways by PHP −
Certain character arrangements beginning with
backslash () are replaced with special characters
Variable names (starting with $) are swapped
with string representations of their values.
The escape-sequence replacements are −
n is replaced by the newline character
r is replaced by the carriage-return character
t is replaced by the tab character
$ is replaced by the dollar sign itself ($)
" is replaced by a single double-quote (")
 is replaced by a single backslash ()
To concatenate two string variables together, use the
dot (.) operator −
<?php
$string1="Hello World";
$string2="1234";
echo $string1 . " " . $string2;
?>
This will produce the following result −
Hello World 1234
The GET method sends the encoded user data affixed to
the page request. The page and the encoded data are
alienated by the ? character.
http://www.test.com/index.htm?name1=value1&name2=
value2
•The GET method creates a long string that appears in
your server logs, in the browser's Location: box.
•The GET method is limited to send upto 1024
characters only.
•Never use GET method if you have password or other
delicate information to be sent to the server.
•GET can't be used to refer binary data, like images or
word documents, to the server.
•The data sent by GET method can be retrieved using
QUERY_STRING environment variable.
•The PHP provides $_GET associative array to access
all the referred information using GET method.
Try out following example by putting the source code
in test.php script.
<?php
if( $_GET["name"] || $_GET["age"] )
{
echo "Welcome ". $_GET['name']. "<br />";
echo "You are ". $_GET['age']. " years old.";
exit();
}
?>
<html>
<body>
<form action = "<?php $_PHP_SELF ?>" method = "GET">
Name: <input type = "text" name = "name" />
Age: <input type = "text" name = "age" />
<input type = "submit" />
</form>
</body>
</html>
The POST method allocations information via HTTP
headers. The information is translated as described in
case of GET method and put into a header called
QUERY_STRING.
The POST method does not have any restraint on data
size to be sent.
The POST method can be used to refer ASCII as well as
binary data.
The data sent by POST method goes through HTTP
header so safety depends on HTTP protocol. By using
Protected HTTP you can make sure that your
information is protected.
The PHP provides $_POST associative array to
admission all the sent information using POST
method.
Try out following example by putting the source code
in test.php script.
<?php
if( $_POST["name"] || $_POST["age"] )
{
if (preg_match("/[^A-Za-z'-]/",$_POST['name'] ))
{
die ("invalid name and name should be alpha");
}
echo "Welcome ". $_POST['name']. "<br />";
echo "You are ". $_POST['age']. " years old.";
exit();
}
?>
<html>
<body>
<form action = "<?php $_PHP_SELF ?>" method = "POST">
Name: <input type = "text" name = "name" />
Age: <input type = "text" name = "age" />
<input type = "submit" />
</form>
</body>
</html>
The PHP $_REQUEST variable contains the stuffing of
both $_GET, $_POST, and $_COOKIE. We will discuss
$_COOKIE variable when we will clarify about cookies.
The PHP $_REQUEST variable can be used to get the
outcome from form data sent with both the GET and
POST methods.
Try out following example by placing the source code
in test.php script.
<?php
if($_REQUEST["name"] || $_REQUEST["age"] )
{
echo "Welcome ". $_REQUEST['name']. "<br />";
echo "You are ". $_REQUEST['age']. " years old.";
exit();
}
?>
<html>
<body>
<form action = "<?php $_PHP_SELF ?>" method = "POST">
Name: <input type = "text" name = "name" />
Age: <input type = "text" name = "age" />
<input type = "submit" />
</form>
</body>
</html>
Here $_PHP_SELF variable contains the name of self script
in which it is being called.

More Related Content

What's hot

The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers
Appili Vamsi Krishna
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
Hyderabad Scalability Meetup
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
durai arasan
 
Perl tutorial
Perl tutorialPerl tutorial
Perl tutorial
Manav Prasad
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
langer4711
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
Open Gurukul
 
Cnotes
CnotesCnotes
The smartpath information systems c pro
The smartpath information systems c proThe smartpath information systems c pro
The smartpath information systems c pro
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
The role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designThe role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler design
Sadia Akter
 
Open Gurukul Language PL/SQL
Open Gurukul Language PL/SQLOpen Gurukul Language PL/SQL
Open Gurukul Language PL/SQL
Open Gurukul
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
Mansi Tyagi
 
C LANGUAGE - BESTECH SOLUTIONS
C LANGUAGE - BESTECH SOLUTIONSC LANGUAGE - BESTECH SOLUTIONS
C LANGUAGE - BESTECH SOLUTIONS
BESTECH SOLUTIONS
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
C language ppt
C language pptC language ppt
C language ppt
Ğäùråv Júñêjå
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
Amarjith C K
 

What's hot (20)

The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
 
Perl tutorial
Perl tutorialPerl tutorial
Perl tutorial
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Cnotes
CnotesCnotes
Cnotes
 
The smartpath information systems c pro
The smartpath information systems c proThe smartpath information systems c pro
The smartpath information systems c pro
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
The role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designThe role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler design
 
Open Gurukul Language PL/SQL
Open Gurukul Language PL/SQLOpen Gurukul Language PL/SQL
Open Gurukul Language PL/SQL
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
Pc module1
Pc module1Pc module1
Pc module1
 
C LANGUAGE - BESTECH SOLUTIONS
C LANGUAGE - BESTECH SOLUTIONSC LANGUAGE - BESTECH SOLUTIONS
C LANGUAGE - BESTECH SOLUTIONS
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
C language ppt
C language pptC language ppt
C language ppt
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
 
Cp module 2
Cp module 2Cp module 2
Cp module 2
 

Similar to Intro to php

Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
SanthiNivas
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
McSoftsis
 
Php web development
Php web developmentPhp web development
Php web development
Ramesh Gupta
 
chapter Two Server-side Script lang.pptx
chapter  Two Server-side Script lang.pptxchapter  Two Server-side Script lang.pptx
chapter Two Server-side Script lang.pptx
alehegn9
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Muthuganesh S
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_masterjeeva indra
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
KIRAN KUMAR SILIVERI
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
Intoroduction to Adnvanced Internet Programming Chapter two.pptx
Intoroduction to Adnvanced Internet Programming Chapter two.pptxIntoroduction to Adnvanced Internet Programming Chapter two.pptx
Intoroduction to Adnvanced Internet Programming Chapter two.pptx
JerusalemFetene
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPrinceGuru MS
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
ravi18011991
 
Php i-slides (2) (1)
Php i-slides (2) (1)Php i-slides (2) (1)
Php i-slides (2) (1)
ravi18011991
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
Abu Bakar
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
zalatarunk
 
php41.ppt
php41.pptphp41.ppt
php41.ppt
Nishant804733
 
PHP InterLevel.ppt
PHP InterLevel.pptPHP InterLevel.ppt
PHP InterLevel.ppt
NBACriteria2SICET
 
php-I-slides.ppt
php-I-slides.pptphp-I-slides.ppt
php-I-slides.ppt
SsewankamboErma
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
Nisa Soomro
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
Mohamed Loey
 

Similar to Intro to php (20)

Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
 
Php web development
Php web developmentPhp web development
Php web development
 
chapter Two Server-side Script lang.pptx
chapter  Two Server-side Script lang.pptxchapter  Two Server-side Script lang.pptx
chapter Two Server-side Script lang.pptx
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Intoroduction to Adnvanced Internet Programming Chapter two.pptx
Intoroduction to Adnvanced Internet Programming Chapter two.pptxIntoroduction to Adnvanced Internet Programming Chapter two.pptx
Intoroduction to Adnvanced Internet Programming Chapter two.pptx
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_master
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
Php i-slides (2) (1)
Php i-slides (2) (1)Php i-slides (2) (1)
Php i-slides (2) (1)
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
php41.ppt
php41.pptphp41.ppt
php41.ppt
 
PHP InterLevel.ppt
PHP InterLevel.pptPHP InterLevel.ppt
PHP InterLevel.ppt
 
php-I-slides.ppt
php-I-slides.pptphp-I-slides.ppt
php-I-slides.ppt
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 

Recently uploaded

Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 

Recently uploaded (20)

Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 

Intro to php

  • 1.
  • 2. PAPER NAME : PROGRAMMING IN PHP STAFF NAME : MS. V. SHANTHI M.sc, M.phil,M.tech,PGDAS. CLASS : III BCA-A SEMESTER : VI
  • 3.
  • 4.
  • 5. PHP is a recursive contraction for "PHP: Hypertext Preprocessor". PHP is a server side scripting language that is implanted in HTML. It is used to accomplish dynamic content, databases, session tracking, even build entire e-commerce sites. It is cohesive with a number of prevalent databases, counting MySQL, Postgre SQL, Oracle, Sybase, Informix, and Microsoft SQL Server. PHP is satisfyingly active in its carrying out, exclusively when pile up as an Apache building block on the Unix side.
  • 6. The MySQL server, once in progress , achieves equal precise composite queries with giant consequence sets in record-setting time. PHP provisions a enormous number of main rules such as POP3, IMAP, and LDAP. PHP4 added provision for Java and dispersed entity planning (COM and CORBA), making n-tier improvement a option for the first time. PHP is tolerant: PHP language tries to be as tolerant as possible. PHP Syntax is C-Like.
  • 7. PHP implements method functions, i.e. from records on a system it can create, open, read, write, and close them. PHP can grip forms, i.e. fold data from files, save data to a file, through email you can send data, reoccurrence data to the user. You add, delete, modify features within your database through PHP. Access cookies variables and set cookies. Using PHP, you can curb users to access some pages of your website. It can scramble data.
  • 8. Five important characteristics make PHP's practical nature possible − Simplicity Efficiency Security Flexibility Familiarity
  • 9. To get a feel for PHP, first start with modest PHP scripts. Since "Hello, World!" is an important example, first we will create a friendly little "Hello, World!" script. <html> <head> <title>Hello World</title> </head> <body> <?php echo "Hello, World!"; ?> </body> </html> It will produce following result − Hello, World!
  • 10.
  • 11. In order to cultivate and run PHP Web pages three vital components need to be installed on your computer system. Web Server − PHP will work with practically all Web Server software, including Microsoft's Internet Information Server (IIS) but then most often used is freely available Apache Server. Download Apache for free here − https://httpd.apache.org/download.cgi
  • 12. Database − PHP will work with practically all database software, including Oracle and Sybase but most commonly used is spontaneously accessible MySQL database. Transfer MySQL for free here − PHP Parser − In order to practice PHP script guidelines a parser must be connected to generate HTML output that can be sent to the Web Browser. This lecture will guide you how to connect PHP parser on your computer. https://www.mysql.com/downloads/
  • 13. Before you ensue it is important to make sure that you have accurate environment setup on your machine to develop your web programs using PHP. Type the following reportinto your browser's address box. http://127.0.0.1/info.php If this displays a page displaying your PHP connection related information then it means you have PHP and Webserver installed properly.
  • 14. Otherwise you have to follow given method to install PHP on your computer. This section will guide you to install and design PHP over the following four platforms − PHP Installation on Linux or Unix with Apache PHP Installation on Mac OS X with Apache PHP Installation on Windows NT/2000/XP with IIS PHP Installation on Windows NT/2000/XP with Apache
  • 15. If you are using Apache as a Web Server then this fragment will guide you to edit Apache Configuration Files. Just Check it here − The PHP configuration file, php.ini, is the final and most instantaneous way to affect PHP's functionality. PHP Configuration in Apache Server
  • 16. Just Check it here − To design IIS on your Windows machine you can refer your IIS Position Guide shipped beside with IIS. PHP.INI File Configuration
  • 17.
  • 18.
  • 19.
  • 20. The main way to collection information in the intermediate of a PHP program is by using a variable. Here are the most imperative possessions to know about variables in PHP. All variables in PHP are signified with a leading dollar sign ($). The value of a variable is the value of its most current assignment. Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be estimated on the right.
  • 21. Variables can, but do not need, to be confirmed before assignment. Variables in PHP do not have inherent types - a variable does not know in improvement whether it will be used to store a number or a string of characters. Variables used before they are dispensed have default values. PHP does a good job of spontaneously exchanging types from one to another when necessary. PHP variables are Perl-like.
  • 22. PHP has a total of eight data types which we use to construct our variables − Integers − are whole numbers, without a decimal point, like 4195. Doubles − are floating-point numbers, like 3.14159 or 49.1. Booleans − have only two possible values either true or false. NULL − is a special type that only has one value: NULL. Strings − are sequences of characters, like 'PHP supports string operations.' Arrays − are named and indexed collections of other values.
  • 23. Objects − are occurrences of programmer-defined classes, which can package up both other kinds of values and functions that are particular to the class. Resources − are special variables that hold locations to resources external to PHP (such as database connections). The first five are simple types, and the next two (arrays and objects) are compound - the compound types can package up other arbitrary values of arbitrary type, whereas the simple types cannot.
  • 24.
  • 25. Simple answer can be given using expression 4 + 5 is equal to 9. Here 4 and 5 are called operands and + is called operator. PHP language supports following type of operators. Arithmetic Operators Comparison Operators Logical (or Relational) Operators Assignment Operators Conditional (or ternary) Operators
  • 26. There are following arithmetic operators supported by PHP language − Operator Description Example + Adds two operands A + B will give 30 - Subtracts second operand from the first A - B will give -10 * Multiply both operands A * B will give 200 / Divide numerator by de-numerator B / A will give 2 % Modulus Operator and remainder of after an integer division B % A will give 0 ++ Increment operator, increases integer value by one A++ will give 11 -- Decrement operator, decreases integer value by one A-- will give 9
  • 27. There are following comparison operators supported by PHP language Operato r Description Example == Checks if the value of two operands are equal or not, if yes then condition becomes true. (A == B) is not true. != Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (A != B) is true. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true. Checks if the value of left operand is less than or
  • 28. There are following logical operators supported by PHP language Operato r Description Example and Called Logical AND operator. If both the operands are true then condition becomes true. (A and B) is true. or Called Logical OR Operator. If any of the two operands are non zero then condition becomes true. (A or B) is true. && Called Logical AND operator. If both the operands are non zero then condition becomes true. (A && B) is true. || Called Logical OR Operator. If any of the two operands are non zero then condition becomes true. (A || B) is true. ! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is !(A && B) is false.
  • 29. There are following assignment operators supported by PHP language − Operato r Description Example = Simple assignment operator, Assigns values from right side operands to left side operand C = A + B will assign value of A + B into C += Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand C += A is equivalent to C = C + A -= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand C -= A is equivalent to C = C - A *= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand C *= A is equivalent to C = C * A /= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand C /= A is equivalent to C = C / A %= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand C %= A is equivalent to C = C % A
  • 30. There is one more operator called conditional operator. This first estimates an expression for a true or false value and then execute one of the two given statements depending upon the result of the evaluation. The conditional operator has this syntax − Operator Description Example ? : Conditional Expression If Condition is true ? Then value X : Otherwise value Y
  • 31.
  • 32. An array is a data structure that stocks one or more related type of values in a single value. For example if you want to collection 100 numbers then instead of defining 100 variables its easy to define an array of 100 length. There are three dissimilar kind of arrays and each array value is retrieved using an ID c which is called array index.
  • 33. Numeric array − An array with a numeric index. Values are stored and retrieved in linear fashion. Associative array − An array with strings as index. This stores element values in connotation with key values rather than in a severe linear index order. Multidimensional array − An array covering one or more arrays and values are retrieved using multiple indices
  • 34. Numeric array:  These arrays can store numbers, strings and any object but their index will be signified by numbers. By default array index starts from zero. Example: Following is the example showing how to create and access numeric arrays. Here we have used array() function to create array. This function is explained in function reference. <html> <body> <?php /* First method to create array. */
  • 35. $numbers = array( 1, 2, 3, 4, 5); foreach( $numbers as $value ) { echo "Value is $value <br />"; } /* Second method to create array. */ $numbers[0] = "one"; $numbers[1] = "two"; $numbers[2] = "three"; $numbers[3] = "four"; $numbers[4] = "five"; foreach( $numbers as $value ) { echo "Value is $value <br />";
  • 36. } ?> </body> </html> This will produce the following result − Value is 1 Value is 2 Value is 3 Value is 4 Value is 5 Value is one Value is two Value is three Value is four Value is five
  • 37. Associative array − The associative arrays are very related to numeric arrays in term of functionality but they are dissimilar in terms of their index.  Associative array will have their index as string so that you can launch a strong suggestion between key and values. To pile the salaries of employees in an array, a numerically indexed array would not be the best choice. Instead, we could use the employees names as the keys in our associative array, and the value would be their separate salary. NOTE − Don't keep associative array privileged double quote while printing otherwise it would not return any value.
  • 38. Example <html> <body> <?php /* First method to associate create array. */ $salaries = array("mohammad" => 2000, "qadir" => 1000, "zara" => 500); echo "Salary of mohammad is ". $salaries['mohammad'] . "<br />"; echo "Salary of qadir is ". $salaries['qadir']. "<br />"; echo "Salary of zara is ". $salaries['zara']. "<br />"; /* Second method to create array. */ $salaries['mohammad'] = "high"; $salaries['qadir'] = "medium"; $salaries['zara'] = "low";
  • 39. echo "Salary of mohammad is ". $salaries['mohammad'] . "<br />"; echo "Salary of qadir is ". $salaries['qadir']. "<br />"; echo "Salary of zara is ". $salaries['zara']. "<br />"; ?> </body> </html> This will produce the following result − Salary of mohammad is 2000 Salary of qadir is 1000 Salary of zara is 500 Salary of mohammad is high Salary of qadir is medium Salary of zara is low
  • 40. Multidimensional array − A multi-dimensional array each component in the main array can also be an array.  And each component in the sub-array can be an array, and so on. Values in the multi-dimensional array are retrieved using multiple index. Example In this example we create a two dimensional array to pile marks of three students in three subjects − This example is an associative array, you can produce numeric array in the same fashion.
  • 41. <html> <body> <?php $marks = array( "mohammad" => array ( "physics" => 35, "maths" => 30, "chemistry" => 39 ), "qadir" => array ( "physics" => 30, "maths" => 32, "chemistry" => 29 ), "zara" => array ( "physics" => 31, "maths" => 22, "chemistry" => 39 ) ); /* Accessing multi-dimensional array values */ echo "Marks for mohammad in physics : " ; echo $marks['mohammad']['physics'] . "<br />"; echo "Marks for qadir in maths : "; echo $marks['qadir']['maths'] . "<br />";
  • 42. echo "Marks for zara in chemistry : " ; echo $marks['zara']['chemistry'] . "<br />"; ?> </body> </html> This will produce the following result − Marks for mohammad in physics : 35 Marks for qadir in maths : 32 Marks for zara in chemistry : 39
  • 43.
  • 44. for − loops through a block of code a definite number of times. Syntax for (initialization; condition; increment) { code to be executed; }
  • 45. while − loops through a block of code if and as long as a quantified condition is true. Syntax while (condition) { code to be executed; }
  • 46. do...while − loops through a block of code once, and then duplications the loop as long as a distinctive condition is true. Syntax do { code to be executed; } while (condition);
  • 47. foreach − loops through a block of code for each component in an array. Syntax foreach (array as value) { code to be executed; }
  • 48. Continue Statement The PHP continue keyword is used to halt the recent iteration of a loop but it does not dismiss the loop. Just like the break statement the continue statement is situated privileged the statement block covering the code that the loop completes, headed by a conditional test. For the pass meeting continue statement, rest of the loop code is hopped and next pass starts.
  • 49. Break Statement The PHP break keyword is used to dismiss the execution of a loop prematurely. The break statement is situated privileged the statement block. It gives you occupied control and whenever you want to exit from the loop you can come out.  After coming out of a loop instant statement to the loop will be executed.
  • 50.
  • 51. If…Else Statement if...else statement − use this statement if you want to accomplish a set of code when a condition is true and another if the condition is not true Syntax if (condition) code to be executed if condition is true; else code to be executed if condition is false;
  • 52. ElseIf Statement Elseif statement − is used with the if...else statement to implement a set of code if one of the numerous condition is true Syntax if (condition) code to be executed if condition is true; elseif (condition) code to be executed if condition is true; else code to be executed if condition is false;
  • 53. Switch Statement switch statement − is used if you want to select one of many blocks of code to be implemented, use the Switch statement. switch (expression) { case label1: code to be executed if expression = label1; break; case label2: code to be executed if expression = label2; break; default: code to be executed if expression is different from both label1 and label2; } Syntax
  • 54.
  • 55.  There are no simulated limits on string length - within the restraints of available memory, you ought to be able to make randomly long strings.  Strings that are enclosed by double quotes (as in "this") are preprocessed in both the following two ways by PHP − Certain character arrangements beginning with backslash () are replaced with special characters Variable names (starting with $) are swapped with string representations of their values.
  • 56. The escape-sequence replacements are − n is replaced by the newline character r is replaced by the carriage-return character t is replaced by the tab character $ is replaced by the dollar sign itself ($) " is replaced by a single double-quote (")  is replaced by a single backslash ()
  • 57. To concatenate two string variables together, use the dot (.) operator − <?php $string1="Hello World"; $string2="1234"; echo $string1 . " " . $string2; ?> This will produce the following result − Hello World 1234
  • 58.
  • 59. The GET method sends the encoded user data affixed to the page request. The page and the encoded data are alienated by the ? character. http://www.test.com/index.htm?name1=value1&name2= value2 •The GET method creates a long string that appears in your server logs, in the browser's Location: box. •The GET method is limited to send upto 1024 characters only.
  • 60. •Never use GET method if you have password or other delicate information to be sent to the server. •GET can't be used to refer binary data, like images or word documents, to the server. •The data sent by GET method can be retrieved using QUERY_STRING environment variable. •The PHP provides $_GET associative array to access all the referred information using GET method.
  • 61. Try out following example by putting the source code in test.php script. <?php if( $_GET["name"] || $_GET["age"] ) { echo "Welcome ". $_GET['name']. "<br />"; echo "You are ". $_GET['age']. " years old."; exit(); } ?> <html> <body> <form action = "<?php $_PHP_SELF ?>" method = "GET"> Name: <input type = "text" name = "name" />
  • 62. Age: <input type = "text" name = "age" /> <input type = "submit" /> </form> </body> </html>
  • 63. The POST method allocations information via HTTP headers. The information is translated as described in case of GET method and put into a header called QUERY_STRING. The POST method does not have any restraint on data size to be sent. The POST method can be used to refer ASCII as well as binary data.
  • 64. The data sent by POST method goes through HTTP header so safety depends on HTTP protocol. By using Protected HTTP you can make sure that your information is protected. The PHP provides $_POST associative array to admission all the sent information using POST method.
  • 65. Try out following example by putting the source code in test.php script. <?php if( $_POST["name"] || $_POST["age"] ) { if (preg_match("/[^A-Za-z'-]/",$_POST['name'] )) { die ("invalid name and name should be alpha"); } echo "Welcome ". $_POST['name']. "<br />"; echo "You are ". $_POST['age']. " years old."; exit(); } ?>
  • 66. <html> <body> <form action = "<?php $_PHP_SELF ?>" method = "POST"> Name: <input type = "text" name = "name" /> Age: <input type = "text" name = "age" /> <input type = "submit" /> </form> </body> </html>
  • 67. The PHP $_REQUEST variable contains the stuffing of both $_GET, $_POST, and $_COOKIE. We will discuss $_COOKIE variable when we will clarify about cookies. The PHP $_REQUEST variable can be used to get the outcome from form data sent with both the GET and POST methods. Try out following example by placing the source code in test.php script. <?php if($_REQUEST["name"] || $_REQUEST["age"] ) { echo "Welcome ". $_REQUEST['name']. "<br />";
  • 68. echo "You are ". $_REQUEST['age']. " years old."; exit(); } ?> <html> <body> <form action = "<?php $_PHP_SELF ?>" method = "POST"> Name: <input type = "text" name = "name" /> Age: <input type = "text" name = "age" /> <input type = "submit" /> </form> </body> </html> Here $_PHP_SELF variable contains the name of self script in which it is being called.