Professional Documents
Culture Documents
Introduction to PHP
A. Chaubal
Introduction to PHP
Introduction to PHP
PHP Hypertext Preprocessor.
Other Names : Personal Home Page, Professional Home
Page
WEB
SERVER
Introduction to PHP
Gets Page
<HTML>
<?php PHP code ?>
</HTML>
HTTP Request
(url)
Server response
CLIENT
Hello
<HTML>
<B>Hello</B>
</HTML>
Browser creates
the web page
A. Chaubal
Introduction to PHP
Why PHP?
..there are no. of server side scripting available like
ASP, SSJS, JSP..
PHP involves
simplicity in scripting (..generally using the database)
platform independence.
PHP is
primarily designed for web applications
well optimized for the response times needed for web
applications
Is an open source.
A. Chaubal
Introduction to PHP
A. Chaubal
Introduction to PHP
Introduction to PHP
PHP Block
PHP code block is embedded within the <?php
and ?> tags.
When the server encounters the PHP tags it
switches from the HTML to PHP mode.
There are four different ways to embed the
PHP code
A. Chaubal
Introduction to PHP
PHP Constants
..values that never changes
Constants are defined in PHP by using the
define() function.
For e.g.
define(NCST, National Centre for Software Technology)
A. Chaubal
Introduction to PHP
PHP Variables
The variables in PHP are declared by
appending the $ sign to the variable name.
For e.g
$company = NCST;
$sum = 10.0;
Introduction to PHP
A. Chaubal
10
Introduction to PHP
PHP Operators
All the operators such as arithmetic,
assignment, Comparison, and logical operators
are similar to the operators in C and C++.
In PHP the string concatenation operator is
denoted by ..
For e.g.
$name = My name is.$myname;
A. Chaubal
11
PHP Statements
Introduction to PHP
IF statement
if (<condition>) {
//php code goes here
}
else {
//php code goes here
}
Alternative Syntax
if(<condition>) :
//html code goes here
else :
//html code goes here
endif;
A. Chaubal
12
Introduction to PHP
}
Alternative Syntax
for($i=0;$i < 10;$++i) :
// html code goes here
endfor;
While loop
Do-While loop
A. Chaubal
13
Introduction to PHP
Functions
Function declaration in PHP
function my_func(<parameters>) {
//do something in the function
}
for e.g.
function sayHello() {
echo(<B>hello amrish<B><BR>);
A. Chaubal
14
Introduction to PHP
Functions (cont.)
Assigning functions to the variables
for e.g
$hello = my_func;
to invoke the function my_func() through the variable
$hello( );
A. Chaubal
15
Introduction to PHP
Arrays
..contains value set
each element has a value, data stored in the
element.
And has a key by which the element can be
referred to.
A. Chaubal
16