PHP is Hyper Text Processor
Other Names : Personal Home Page, Professional Home Page
Is a server side scripting language.
Capable of generating the HTML pages
HTML generates the web page with the static text and images.
However the need evolved for dynamic web based application, mostly involving database usage.
http://phptraininginjaipur.info/
3. What is PHP ??
PHP is Hyper Text Processor
– Other Names : Personal Home Page, Professional
Home Page
• Is a server side scripting language.
– Capable of generating the HTML pages
• HTML generates the web page with the static text and
images.
• However the need evolved for dynamic web based
application, mostly involving database usage.
• http://phptraininginjaipur.info/
5. PHP Language Features
• PHP language features such as control structures,
operators, variable types, function declaration,
class/object declaration are almost similar to any
compiled or interpreted language such as C or C++.
• http://phptraininginjaipur.info/
6. PHP Data Types
Three basic data types
– Integer
– Double
– String
• More data types
– Array
– Object
• PHP is an untyped language
– variables type can change on the fly.
–http://phptraininginjaipur.info/
7. 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”)
• defined() function says whether the constant
exists or not.
• http://phptraininginjaipur.info/
8. PHP Variables
• The variables in PHP are declared by appending the $
sign to the variable name.
– For e.g
$company = “NCST”;
$sum = 10.0;
• variable’s data type is changed by the value that is
assigned to the variable.
• Type casting allows to change the data type explicitly.
• http://phptraininginjaipur.info/
9. 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;
• http://phptraininginjaipur.info/
10. PHP Statements
• 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;
http://phptraininginjaipur.info/
11. PHP Statements (cont.)
• For loop
for($i=0;$i < 10;$++i) {
echo(“the value is :”. $i);
}
– Alternative Syntax
for($i=0;$i < 10;$++i) :
// html code goes here
endfor;
• While loop
• Do-While loop
• http://phptraininginjaipur.info/
12. 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
• http://phptraininginjaipur.info/
13. Initializing Arrays
• No of ways to initialize the array.
– For e.g.
• $ncststaff[] = “amrish”;
$ncststaff[] = “murali”;
$ncststaff[] = “narayan”;
• $ncststaff[123] = “amrish”;
$ncststaff[122] = “murali”;
$ncststaff[121] = “narayan”;
• $ncststaff = array (“amrish”, “murali”, “narayan”);
– to change the indices of the array use => operator.
–http://phptraininginjaipur.info/
14. Accessing the Array Elements
– Array_walk(<arrayname>,<function_name>)
• function_name is the function that is written for every member of
an array.
• For e.g
$ncststaff = array (“amrish”, “murali”, “narayan”);
array_walk ($ncststaff, printstaff);
// function to print each element of the array
function printstaff($names) {
echo “<B>$names</B><BR>n”;
}
http://phptraininginjaipur.info/