php basic part1
DESCRIPTION
in this presentation i try to explain basic fundamentals of php.TRANSCRIPT
MyBlog = http://excellentprogramming.blogspot.com
BASICS OF PHP PART1Author –Subhasis Nayak
04/1
0/2
023
1
MyBlog = http://excellentprogramming.blogspot.com
WHY $PHP ? Hi! Friends the day has gone when we designed our
website with only html.On those days internet is used for only collect information. But now a days we are in web2.0 world of internet.
Now a days each and every one is on internet. Each one is socializing him selves.More and more companies coming to internet world to sell products or stay with their customers.
So we can not stay with html to provide a high end site like facebook.com , youtube.com, ebay.com, blogger.com,ibibo.com and etc.
04/1
0/2
023
2C
op
y rig
ht o
f - Su
bh
asis
N
ayak
MyBlog = http://excellentprogramming.blogspot.com
$CONTINUE .... Oh ! Yes you may ask me, why we choose
php rather choosing a language like jsp,asp or etc.
Answer is very simple .PHP is open source and easily compatable with the cheaper and secured database like MYSQL.
Next is more than 70% web site owner choosing php,mysql server due to the less price and high end performance.
04/1
0/2
023
3C
op
y rig
ht o
f - Su
bh
asis
N
ayak
MyBlog = http://excellentprogramming.blogspot.com
$CODE DISSECTION Well just below there is a line of php code. In
this code first and last part is most. Which tells the web server to start and end of php block or code. You must write any php code inside the php block else you will get errors.
04/1
0/2
023
4C
op
y rig
ht o
f - Su
bh
asis
N
ayak
<?php echo “Welcome to PHP programming” ; ?>
MyBlog = http://excellentprogramming.blogspot.com
$VARIABLES It is the symbolic representation of the value. As
the name suggest it can change over time. It can contain.In PHP it has some sort of rules for variable naming as follows. It must start with a dollar sign Followed by a letter, under score It must not contain any space else php will think it as
a different entity. It can contain letters, numbers, underscores or
dashes. It is case sensitive.
04/1
0/2
023
5C
op
y rig
ht o
f - Su
bh
asis
N
ayak
MyBlog = http://excellentprogramming.blogspot.com
$CONTINUE .... In php we are not using type of value it is
going to be store a like other programming lanuage. So we just use a dollar sign ”$” and variable name. When we store a value it automatically detects the type and works on it. Declaration and value assigning in php as below. $urname,$ur_name,$Urname - (declaring a
variable) $urname = “Subhasis Nayak”; $age = 25;
04/1
0/2
023
6C
op
y rig
ht o
f - Su
bh
asis
N
ayak
MyBlog = http://excellentprogramming.blogspot.com
04/1
0/2
023
7C
op
y rig
ht o
f - Su
bh
asis
N
ayak
$VALIDE VARIABLES.Good variables Bad variables
$itemname $item-name
$Itemname $item__name
$item_name $_itemname
$itemName
$item0
Php itself used this type
You might confused with subtraction sign
You might confused with number of dashes
MyBlog = http://excellentprogramming.blogspot.com
$HOW TO USE VARIABLES ? Examples of the naming variables: -
$employee_name
04/1
0/2
023
8C
op
y rig
ht o
f - Su
bh
asis
N
ayak
<?php$myvariable = 200;echo $myvariable;$myVariable =”Welcome to Nayak world”;echo $myVariable;$myvariable=500;echo $myvariable; ?>
MyBlog = http://excellentprogramming.blogspot.com
EXPLANATION OF PROGRAM <?php?> - these two are php strat and end
tags. All codes must be inside of this to run else we will get errors.
04/1
0/2
023
9C
op
y rig
ht o
f - Su
bh
asis
N
ayak
$myvariable = 200;$myVariable =”Welcome to Nayak world”;$myvariable=500;
Variables with values
echo $myvariable;Displays the value of the variavle
MyBlog = http://excellentprogramming.blogspot.com
04/1
0/2
023
Cop
y rig
ht o
f - Su
bh
asis
N
ayak
10
USING VARIABLE
On left hand side i just put a value ‘100’ to variable name $myVar. Once here we asign the value w can echo(display) or use it. Here we can put another value to variable $myVar.
Here we display the value then we assign another value and display it. Go to my blog for downloading the source code for this program.
<?php
$my Var = 100;
echo ”value on variable ” .$myVar. ”</br>”;
$my Var = 500;
echo ”value on variable ” .$myVar. ”</br>”;
?>
MyBlog = http://excellentprogramming.blogspot.com
04/1
0/2
023
Cop
y rig
ht o
f - Su
bh
asis
N
ayak
11
CASE SENSITIVITY
You must dwonload the program casesensitivity.php and run it. Tell me what you will find. Put the answer as comment just below the post. I will check reply you the answer why it is so. If you get that why so? Then comment it.
<?php
$my Var = 100;
echo ”value on variable ”.$myVar. ”</br>”;
$my Var = 500;
echo ”value on variable ” .$myvar. ”</br>”;
?>
MyBlog = http://excellentprogramming.blogspot.com
$NUMBERS IN PHP We can do math works as we do in other
programming language. Let’s check some example.
04/1
0/2
023
12C
op
y rig
ht o
f - Su
bh
asis
N
ayak
$mynumber =10;$mynumber +=10; ans=20$mynumber -=10; ans=10$mynumber *=10; ans=100$mynumber /=10; ans=10Increment &decrement:-$mynumber++ $mynumber- -
MyBlog = http://excellentprogramming.blogspot.com
$FLOATING POINT NUMBERS We can work with floating point number a in other
programming languages. Be careful there is nothing special to create a floating point in PHP. Some of them are as below.
Rounding up the floating point:-
04/1
0/2
023
13C
op
y rig
ht o
f - Su
bh
asis
N
ayak
$varfloat =3.14;echo 12/5;
Round($varfloat,1); ans=3.1 (rounded one decimal point)Ceil($varfloat); ans=4 (it rouned up tp next integer)Floor($varfloat); ans=3 (it rounds up previous integer)
MyBlog = http://excellentprogramming.blogspot.com
$STRINGS IN PHP
In PHP we can use strings in a different ways. We can print a whole string with the help of echo
and double quote (“”) as below Example: - echo “Welcome to PHP world”;
We can print a whole string with the help of echo and single quote (‘’) as below Example:- echo ‘welcome to the drupal’;
04/1
0/2
023
14C
op
y rig
ht o
f - Su
bh
asis
N
ayak
MyBlog = http://excellentprogramming.blogspot.com
CONTINEUE ....
We can assign the a string to a variable as like below. Example: - $my_string =”Hi, Do you know, Joomla is
very powerful”; can do concatenations like below.
Example: - echo $my_variable. “wow!”; We can print a string with a variable combinedly
as below. Example: - echo $my_string. ” a CMS”;
04/1
0/2
023
15C
op
y rig
ht o
f - Su
bh
asis
N
ayak
MyBlog = http://excellentprogramming.blogspot.com
$STRING FUNCTIONS There are a lot of predefined string functions
in PHP. We can collect the information about them from http://php.net . some of them as below Concatenation –
Example:- $my_string1=”HI! Good morning”;
04/1
0/2
023
16C
op
y rig
ht o
f - Su
bh
asis
N
ayak
$my_string1=”HI! Good morning”;$my_string2=” and have a nice day”;$my_string3=$my_string1;$my_string3 .=$mys_tring2 ;echo $my_string3;
MyBlog = http://excellentprogramming.blogspot.com
CONTINUE .... Lowercase and uppercase-
04/1
0/2
023
17C
op
y rig
ht o
f - Su
bh
asis
N
ayak
$mystring = “I AM A PROGRAMMING ROBOT”;$my_lower = strtolower($mystring);echo $my_lower;$mystring =“programming is my hobby”;$my_upper = strtoupper ($mystring);echo $my_upper;
MyBlog = http://excellentprogramming.blogspot.com
CONTINUE .... Uppercase of first character of the sentence.
Upper casing the first character of each word .
04/1
0/2
023
18C
op
y rig
ht o
f - Su
bh
asis
N
ayak
$my_string1 = “hello! Mr. Guest”;$my_str = ucfirst($my_string1);echo $my_str;
$my_string2 = “hello! Mr. Someone”;$my_lower = ucwords($my_string2);echo $my_str;
MyBlog = http://excellentprogramming.blogspot.com
$ MEET YOU ON NEXT SESSION On next session We will disscuss on
Arrays and arrays functions Type casting Constants Control structures
04/1
0/2
023
19C
op
y rig
ht o
f - Su
bh
asis
N
ayak
Thank youTil l then bye bye.