SlideShare une entreprise Scribd logo
1  sur  218
1
2
HTML
HTML is a not a scripting language or programming language.It is a
simple markup language with the pair of markup tags.
The first tag is known as opening tag (or) starting tag. The second tag
is known as closing (or) end tag.
HTML is used to describe the web pages.
HTML can be written in notepad, notepad++, dream viewer, adov and
cs5.
HTML file can be saved with .html as its extension.
The look end of an web page should be same on the all browsers. If it
is not same the cross browser compatibility.
Tags in html :
Heading tags are h1, h2,h3,h4,h5,h6
Ex: - <h1>welcome to html</h1>
.
.
<h6> welcome to html</h6>
<hr>: - this tag is used for horizontal line
<br>: - this tag is used for break
<p>: - this tag is used for paragraph content
<b>: - this tag is used for bold content
<i>: - this tag is used for italic content
<link>: - this tag is used for connect the style sheets
<script>: - this tag is used for JavaScript
<big>: - this tag is used for big content
3
<strong>: - this tag is used for strong content
<blink>: - this tag is used for blink content
<del>: - this tag is used for delete the content
<strike>: - this tag is used for strike
<u>: - this tag is used for underline content
<ins>: - this tag is used for insert content
<q>: - this tag is used for quotation content
<sup>: - this tag is used for super content
Ex: - (a+b) <sup> 2</sup>
<sub>: - this tag is used for subscript content
Entities :
Entities are used to describe the symbols (or) special characters on to
the web page. We have certain symbols are not available on the
keyboard. So such symbols can be inserting through entities. We have
mainly two types of entities they are
1. Named Entity
2. Number Entity
1. Named Entity :
Syntax: - Ampersand + entity name + semicolon
Ex: -&dollar;
2. Number Entity :
Syntax: Ampersand + hash + ascci value+ semicolon
Ex : &#65; =>A
&#153; =>Trademark: tm
4
List Tags :
List tags are two types
1. Order list : Grouping of elements in the form of order wise
through number, upper alpha (A),lower alpha (a), upper roman, lower
roman is known as order list
Ex: - Order list.html
<ol type='a' start='25'>
<li>Nokia</li>
<li>Mototola</li>
<li>Sony</li>
</html>
2. Unorder list : Grouping of elements in the form of disk, square
circle are known as unorder list
Ex: -
<ul type='square'>
<li>PHP</li>
<li>HTML</li>
</ul>
Definition list : This is used to maintain the heading the description
on to the <dl> tag.
Definition term : Definition term creates the heading
Definition description : Which holds the description of the content.
Dt and dd tags are both child tags of DL.
Ex :
<dl>
<dt>Terms & Conditions</dt>
5
<dd><small><small>some large text matter write here
</small></small></dd>
</dl>
Meta tag :
Meta tag is used to generate the traffic on to your web page. Meta tags
can be embed into the head tag using Meta tag.
 Meta tag helps in search engine ranking on Google page and
PTC(pay to click)
Ex : Meta.html
<html>
<head>
<title>Meta Tags</title>
<meta name='keyword'
content='PHP,HTML,JQUERY,CSS,HYDERABAD,Institute,Ameer
pet'/>
<meta name='description' content='We been in lamp for more than
8years and trained many student ... many have got jobs in PHP ...'/>
<meta http-equiv='refresh' content='5;url=http://www.axis-
bank.com'/>
</head>
<body>
<h2>We have changed our Website Name from UTI Bank to AXIS
Bank ... Sorry for incontinent Please wait for 5 sec it would be
Automatically be Redirected</h2>
</body>
</html>
6
Link tags :
Links are used to navigate from one page to another page using inter
(or) external links.
The attributes we can pass are
Target = “-blank” // new web page
Target = “-new” // new web page
Target = “-self” // open on same page
Links can target to mails and also search the link on same page.
Ex : linktag.html
<html>
<head>
<title>Link Tags</title>
</head>
<body>
<h3>Links Navigation</h3>
<a href='http://www.google.com' target="_blank">Google page</a> ||
<a href='http://www.facebook.com' target='_self'>Facebook Page</a>
||
<a href='Tags.html' target="_new"> Tags Content</a>
</body>
</html>
Image tags:
Images can be embed into the body tag using image tag. Images have
extension of jpg, png, gif etc.,
7
Placing one image on to the web page can be done by two types they
are
1.Absolute Path
2.Relative Path
1. Absolute path : Working from the working directory you can call
the image from anywhere with respect to its parent directory (or) out
of the parent directory (or) external files.
Ex :
<h2>absolute path</h2>
<img src = ‘http://www.google.com/images/mountain.jpg’ alt =
‘beautiful’ border = ‘10’ width = ‘200px’ height = ‘180px;/>
2. Relative path : Using relative path you can work with images on
to the same current working directory (or) sub folders did not out of
your parent directory.
Ex :
<h2>relation tags</h2>
<img src="suresh.jpg" width='140px' height='150px' border='0'
title='suresh'/><br>
<img src="../water lilies.jpg" width='200px' height='180px' border='3'
title='suresh'/><br>
<img src="../../sunset.jpg" width='200px' height='180px' border='3'
title='suresh'/><br>
<img src="new folder/dsc_0083.jpg" width='200px' height='180px'
border='3' title='suresh'/><hr>
Tables create :
Tables are used to put down content in tabular structure. Table tag can
be embed into your body tag using
<table>
8
<tr> table row</tr>
<td> table data (or) content</td>
</table>
 The general attributes that we can pass in table tag are
Border = “<num>”
Width = “<num>”
Height = “<num>”
Cellpadding = “<num>”
Cellspacing = “<num>”
Align= left/center/right
Background = “image path”
Fames = “box/group/lhs/rhs/above/below/vsides/hsides
Rules = all/middle/bottom
Colspan =“<num>”
Rowspan = “<num>”
Bgcolor = “color name”
Ex :
<body>
<table border = “1” align = “center” width = “70%”>
<tr><td>employee detailsl</td></tr>
<table>
<tr><td>s.no</td><td>Name</td><td>designation</td></tr>
<tr><td>1</td><td>suresh</td><td>php programmer</td></tr>
</body>
Cell padding : Cell padding is used to maintain the distance between
its content and from its wall (or) border
Cell spacing : Cell spacing is used to increase the wall (or) the
border
9
Frame set :
We can divide the body into number of divisions that are passed as an
argument based on rows (or) columns working with frame set you
should ensure that body tag is not given
Note : Frame set is a depreciated tag and would be working with
future versions
Ex :
<frameset cols='30%,25%,*'>
<frame src = 'links.html' scrolling='no' >
<frame src = 'entities.html' >
<frame src = 'list.html' >
</frameset>
Iframes :
Ex :
<body>
<p align='center'><a href='list.html' target='x'>List Page</a> | <a
href='links.html' target='x'>Links Page</a><br><br>
<iframe src='list.html' name='x' width='600px' height='200px'
></iframe></p>
</body>
10
11
Cascading Style Sheets(CSS)
Css stands for cascading style sheet. Css is used to put some styles
(or) colors on to the web page. Css can be embed into the html head
tag using style tag. There are mainly 3 different flavors to attach this
style on to the web page. Which are mainly
1. Internal style sheet
2. External style sheet
3. In-line style sheet
1. Internal style sheet :
An internal style sheet should be used when a single document has a
unique style. You define internal styles in the head section of an
HTML page, by using the <style> tag, like this:
<head>
<style type="text/css">
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("images/back40.gif");}
</style>
</head>
2. External style sheet :
An external style sheet is ideal when the style is applied to many
pages. With an external style sheet, you can change the look of an
entire Web site by changing one file. Each page must link to the style
sheet using the <link> tag. The <link> tag goes inside the head
section:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
12
An external style sheet can be written in any text editor. The file
should not contain any html tags. Your style sheet should be saved
with .css extension. An example of a style sheet file is shown below:
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("images/back40.gif");}
3. In-line style sheet :
An inline style loses many of the advantages of style sheets by mixing
content with presentation. Use this method sparingly!
To use inline styles you use the style attribute in the relevant tag. The
style attribute can contain any CSS property. The example shows how
to change the color and the left margin of a paragraph:
<p style="color:sienna;margin-left:20px">This is a paragraph.</p>
We have one more style which is given by default by browsers which
is not editable
External style sheet can be saved with .css as its extension
Syntax :
(Attributes) element (or) class (or) id {property: value ;}
CSS Syntax :
A CSS rule has two main parts: a selector, and one or more
declarations:
The selector is normally the HTML element you want to style.
Each declaration consists of a property and a value.
13
The property is the style attribute you want to change. Each property
has a value.
Selector :
Selectors are identifiers which give styles based on elements, class
(denoted by period ‘.’), id (denoted by ‘#’).We have 7 kinds of
selectors.They are :
 Element selector
 Class selector
 Class with element selector
 Id selector
 Id with element selector
 Attribute selector
 Pseudo selector
1.Element selector :
Ex : element.html
<html>
<head>
<title>Element Selector</title>
<style>
h1{color:green;}
</style>
</head>
<body>
<h1>Welcome to my Website</h1>
</body>
</html>
14
2.Class selector :
The class selector is used to specify a style for a group of elements.
Unlike the id selector, the class selector is most often used on several
elements.
This allows you to set a particular style for many HTML elements
with the same class.
The class selector uses the HTML class attribute, and is defined with
" . (dot)"
In the example below, all HTML elements with class="center" will be
center-aligned:
3.Class with Element Selector :
Example for Class Selector and Class with Element Selector
Ex : class-selector.html
<html>
<head>
<title>Class with Element Selector</title>
<style>
h1{color:green;} //element selector
.x{color:red;} // class selector
//.x{font-family:impact;}
p.x{font-size:20pt;color:black;} // Class with element selector
</style>
</head>
<body>
<h1>Welcome to my Website</h1>
15
<h1 class='x'>This is new Website </h1>
<h1>hello This is my next line</h1>
<p class='x'>Hello my next page</p>
<p>Rajesh</p>
</body>
</html>
4.Id selector :
The id selector is used to specify a style for a single, unique element.
The id selector uses the id attribute of the HTML element, and is
defined with a "#".
The style rule below will be applied to the element with id="para1":
5.Id with Element Selector :
Example for Id Selector & Id with Element Selector
Ex : Id-selector.html
<html>
<head>
<title>Id with Element Selector</title>
<style>
h1{color:green;} //element selector
.x{color:red;} // class selector
//.x{font-family:impact;}
p.x{font-size:20pt;color:black;} // Class with element selector
#g{background:green;} //id selector
p#g{text-transform:uppercase;} //id with element selector
16
</style>
</head>
<body>
<h1>Welcome to my Website</h1>
<h1 class='x'>This is new Website </h1>
<h1>hello This is my next line</h1>
<p class='x'>Hello my next page</p>
<p class='x' id='g'>Rajesh</p>
<h2 class='x' id='g'>Amith</h2>
<h2 class='x' id='g'>David</h3>
<p class='x' id='g'>Praveen</p>
<p class='x' id='g'>Karthik</p>
</body>
</html>
6.Attribute selector :
Ex : attribute.html
<html>
<head>
<title>Attribute Selector</title>
<style>
.x{
color:deeppink;
font-family:impact;
}
17
input[type='text']{
color:deeppink;
}
</style>
</head>
<body>
Name : <input type='text’ name='name' class='x'><br>
username : <input type='text' name='uname'><br>
</body>
</html>
7.Pseudo selector :
Ex : pseudo.html
<html>
<head>
<title>Pseudo Selector</title>
<style>
p:first-letter{
font-size:30pt;
color:deeppink;
font-family:arial black;
}
p:first-line{
color:orange;
}
18
</style>
</head>
<body>
<p>This is my first email to all you guys his is my first email to all
you guys his is my first email to all you guys his is my first email to
all you guys his is my first email to all you guys</p>
</body>
</html>
Css cheat sheet :
Font-styles :
font-style : italic,normal
font-variant : small-caps,narmal,small,caps(capital letters)
font-weight : normal,lighter,bold, bolder, number(100->light,
900->bolder)
font-size : <num> px;
font-family : family of font
Text properties :
1. letter-spacing : <num>px
2. word-spacing : <num>px
3. line-height : <num>px
4. text-align : left/center/right/justify ->order from left (or) right
5. text- decoration : name, blink,underline,overline,line-through
6. text-transform : capitalize(upper case/lower case(everything
convert))
7.text-indent : <num>px (distance from line to first letter)
19
 The text-align property is used to set the horizontal alignment of
a text. Text can be centered, or aligned to the left or right, or
justified. When text-align is set to "justify", each line is
stretched so that every line has equal width, and the left and
right margins are straight (like in magazines and newspapers).
 The text-decoration property is used to set or remove
decorations from text. The text-decoration property is mostly
used to remove underlines from links for design purposes:
 The text-transform property is used to specify uppercase and
lowercase letters in a text.It can be used to turn everything into
uppercase or lowercase letters, or capitalize the first letter of
each word.
 The text-indent property is used to specify the indentation of the
first line of a text.
Background property :
CSS background properties are used to define the background effects
of an element.
background-color : ‘color name’;
background-image : url(image path name);
The background-image property specifies an image to use as the
background of an element.
By default, the image is repeated so it covers the entire element.
The background image for a page can be set like this:
background-repeat : no-repeat,reapt-x,reapt-y,repeat(*);
By default, the background-image property repeats an image both
horizontally and vertically.
Some images should be repeated only horizontally or vertically, or
they will look strange, like this:
background-attachment : fixed,scroll;
20
background-position :{x,y}left,center,right,bottom,top
When using a background image, use an image that does not disturb
the text.
Showing the image only once is specified by the background-repeat
property:
//background : order wise
List properties :
list-style-type : none,disk,circle,square,decimal,upper-alpha,lower-
alpha,upper-roman,lower-roman;
list-style-position : outside (*) / inside;
list-style-image:url(image path name);
Box properties :
Padding : inside element
Margin auto = center
Overflow = visible (*), hidden, auto, scroll
Ex :
<html>
<head>
<title>BOX properties</title>
<style>
//body{margin:0px;}
p{text-align:center;}
.z{
background:#ccc;
padding:15px;
21
width:50%;
height:80px;
margin:auto;
overflow:auto;
text-align:justify;
}
</style>
</head>
<body>
<p>
<input type='checkbox' name='t&c' />Terms & Conditions
<p class='z'>
Some large text matter</p>
</p>
</body>
</html>
Border Properties :
border-width : <num>px;
border-style : solid,groove,inset,outset,double,dotted,dashed;
border-color : <color name>
//border: order wise
Div tag :
Div tag stands for division tag.Div tag is the block level element. A
block level element creates a block with coming left and right breaks
in it.
22
Ex : div tag, p tag, h1 to h6, table tag, ul and li tags
In-line element : These particular elements will take the content
span only and does not have breaks init
Span tag is the natural tag.
Ex :
<html>
<head>
<title>in-line element</title>
<style>
h1 {
background : green; display : inline;
}
b{
Background: gold;
}
a.{text-align : center; background : yellow; display : block;
}
</style>
</head>
<body>
<h1>hello</h1><b>hello</b><i>hello</i><p>hello</p> <hr>
<span class = ‘a’>hello</span>
<div class = ‘a’>hello</div> <hr>
<h3> converting block & inline & respectively<h3>
<h1> hello</h1>
23
</bold>
</html>
Display properties :
Visibility : we have visible (or) hidden
Display : none, in-line, block;
Padding : <num>px all sides
Padding : top left
0px 0px
Bottom right
Margin : <num> all sides
Margin : top right bottom left
0px 0px 0px 0px
Templates :
Position properties : Position in css we have absolute, relative and
fixed position
Relative position : Working from the current position we can move
the element anywhere on to the web page but cannot be moved on the
top of the position place.
Absolute & fixed position : Placing from the current position we
can move the element to all corner of the web page and also one top
of the position place .once an element declare as fixed (or) absolute
this will turn to in-line element and this will also carry ‘7’ index init
Ex : position.html
<html>
<head>
<title>Position properties</title>
24
<style>
div{background:blue;color:#fff;font-size:17pt; font-
weight:bold;padding:10px;margin:4px;}
.r{background:gold;color:#000;position:relative;left:30px;top:120px;}
.a{background:blue;position:absolute;top:50px;left:6px;}
.f{background:deeppink;color:#000;position:fixed;bottom:0px;right:0
px;}
</style>
</head>
<body>
<div>Normal Position</div>
<div class='a'>Absolute Position</div>
<div class='r'>Relative Position</div>
<div class='f'>Fixed Position</div>
<h1>some large text matter </h1>
<h1> some large text matter </h1>
<h1> some large text matter </h1>
<h1> some large text matter </h1>
</body>
</html>
25
26
JavaScript
 JavaScript is client side scripting language.
 JavaScript is the case sensitive.
 JavaScript can be used for AJAX integration and validation.
 JavaScript can be embed into the head tag and body tag using
script tag.
 JavaScript can be saved with .js as its extension.
Content:
 Variables
 Datatypes
 Operators (Assignment, Arthamatic, Post/Pre [Inc/Dec],
Comparission, Relational, Conditional, Logical,Ternary)
 Alert,prompt,confirm
 Built in Functions (Arrays,Date,Math,String)
 DOM (Document Object Module)
 Navigator,images,screen,location,history
 Document – (getElementById, getElementsByTagName,
getElementsByName)
 Events :
 General Events (onclick(), ondblclick(), onload(),
onunload(), onreset(), onsubmit(), onfocus(), onblur(),
onchange())
 Mouse Events (onmouseover(), onmousemove(),
onmousedown(), onmouseout() )
 Key Board Events – (onkeyup() , onkeydown() )
Document.write () :
document.write is the printing method in javascript.Which is output
statement to the browser.
Ex: first.html
<html>
<head>
27
<script src='ext.js' type='text/javascript'
language='javascript'></script>
<script>
document.write('This is Called from Head Tag<br>');
</script>
</head>
<body>
<h1>Welcome</h1>
<script>
document.write('This is Called from Body Tag<br>');
</script>
</body>
</html>
ext.js:-
document.write('<h1>This is called from External Page</h1>');
Variables :
Variables are case sensitive. Declaring a variable in JavaScript as
variable name = value;
Variables are "containers" for storing information.
Ex : var a = 10; var = default
The correct method to declare are :
Var a = 10;
Var_a = 10;
Var first-name = ‘suresh’;
28
Var firstName = ‘suresh’;
Var $name = ‘suresh’;
Wrong method :
Var #name = ‘suresh’;
Var 1a = 10;
Var first name = ‘suresh’;
Data Types :
String :
Collection of characters inside a single (or) double quotations are
known as string ,working with single quotation and adding double
quotation in it is valid.But adding single quotation inside a single
quotation is not valid.
Ex : datatypes.html
<html>
<head>
<script>
var a = 10;
document.write('<h1>'+a);
document.write(' - ');
document.write(typeof(a));
document.write('<br>');
var f = 10.25;
document.write(f);
document.write(' - ');
document.write(typeof(f));
29
document.write('<br>');
firstname = 'Rajesh';
document.write(firstname+' - '+typeof(firstname)+'<br>');
firstname = firstname+' Kumar';
document.write(firstname+' - '+typeof(firstname)+'<br>');
firstname += 'B';
document.write(firstname+' - '+typeof(firstname)+'<br>');
document.write('<hr>String Methods<hr>');
document.write('i'll Pay the Bill Tomorrow');
</script>
</head>
<body>
<h1>Welcome</h1>
</body>
</html>
Operators :
1.Assignment operator: ‘ = ‘ is used to assign values.
The assignment operator ‘=’ is used to assign values to JavaScript
variables.
Ex :
<script>
document.write('<h1 align="center">Assignment Operator</h1>');
var x = 10;
30
document.write("The Value is : "+x);
</script>
2.Arithmetic operator: -
The arithmetic operator ‘ +’ is used to add values together.
Arithmetic operators are used to perform arithmetic between variables
and/or values.
Ex :
<script>
document.write('<h1 align="center">Arthamatic Operator</h1>');
a = 5; b = 3;
document.write("Addition : "+(a+b)+'<br>');
document.write("Multiplication : "+(a*b)+'<br>');
document.write("Division : "+(a/b)+'<br>');
document.write("Minus : "+(a-b)+'<br>');
document.write("Modulus : "+(a%b)+'<br>');
</script>
3.Comparision operator :
Comparision operators are used in logical statements to determine
equality or difference between variables or values.
Ex :
<script>
Document.write('<h1 align="center">comparision Operator</h1>');
if(10 != '10'){
31
document.write('<h2>Correct</h2>');
} else {
document.write('<h2>Not Correct</h2>');
}
document.write('<h1 align="center">Post & Pre Increment</h1>');
m = 10;
n = (m++)+(++m)+(m++)+(++m);
document.write('The Value of m is : '+m+'<br>The Value of n is :
'+n+'<br>');
</script>
4.Relational operator : < , > , <= , >=
5.Logical operator : &&(and) -- ||(or)
6.Ternary operator :
Syntax for Ternary Operator :
Var a= 10;
Type = (a%2 == 0)? ‘even number’: ‘odd number’;
//document.write(“the value you entered is : ”+type);
document.write(type);
Conditions :
1.If else :
Whenever a condition is ‘if’ it is true that part of the constructor will
be excuted.if condition is fail ‘else’ part would get executed.
32
 Conditional statements are used to perform different actions
based on different conditions
 use this statement to execute some code if the condition is true
and another code if the condition is false
Syntax :
If (cond)
{
//code
}
else
{
// code
};
2.If else if :
if else if (or) ladder condition will take more than one condition (or)
multiple conditions. If all the conditions fail in if else if constructor
then only else part get executed
 Use this statement to select one of many blocks of code to be
executed
Syntax :
If(cond)
{
//code
}
33
else if (cond)
{
//code
}
else if (cond)
{
//code
}
.
.
else
{
//default value;
}
3.Switch :
Use the case in-order wise. This is main concept in switch case
 Use this statement to select one of many blocks of code to be
executed
 Conditional statements are used to perform different actions
based on different conditions.
Syntax :
switch(n)
{
case 1: execute code block 1
34
break;
case 2: execute code block 2
break;
default:
code to be executed if n is different from case 1 and 2
}
Looping methods :
While:
do-while:
Syntax:
Syntax:
Initialize method
Initialize
While (cond)
do
{
{
//code
//code
}
}
1.While :
Working with while loops it will first check the initialize part and
checks the condition. If condition is true it will get into the
constructor and takes place until condition fail and comes out of the
constructor.
 loops through a block of code while a specified condition is true
35
2.Do-while :
This will also checks the initialized part .but for only first time it will
get into the constructor and execute the code and checks the
conditions later and if condition is true looping takes place (or) else it
come out of the constructor with at least single time execution code
3.For-loop :
For loop first initialize condition an inc/dec will be done on same
(single) line for the every first time it will initialize with part them
check within condition if condition is true the constructor will get
excuted.condition fail will come out of the for loop (constructor)
 Loops execute a block of code a specified number of times, or
while a specified condition is true.
Syntax :
For (initialize; condition; inc/dec )
{
//code
}
Arrays :
A variable which can hold more than one value is none as array (or)
super variable as array can be defined is JavaScript as
Var a = new Array (values); // a->super variable
 To find the length of the array we can go with length = array
name.length;
 If the array index is been initialize more than the current
index++ then memory is wasted in JavaScript
 In arrays initializing string index the printing method will not
work in JavaScript
Note : - document.write() (or) looping method will not able to print
string indexes
36
 While, do-while , for-loop will not print string indexes in
JavaScript so to print string indexes we can go with
Syntax: - for (var name in Array name)
 For is key word in JavaScript which will print the string index
 The Array object is used to store multiple values in a single
variable.
 An array is a special variable, which can hold more than one
value, at a time.
Create an Array :
An array can be defined in three ways.
The following code creates an Array object called myCars:
1: var myCars=new Array(); // regular array (add an optional integer
myCars[0]="Saab"; // argument to control array's size)
myCars[1]="Volvo";
myCars[2]="BMW";
2: var myCars=new Array("Saab","Volvo","BMW"); // condensed
array
3: var myCars=["Saab","Volvo","BMW"]; // literal array
Ex : Array.html
<script>
var a = new Array(10,20,30,40);
document.write('The Array is : '+a+'<br>');
document.write('Length of Array : '+a.length+'<br>');
document.write('Index at 2 : '+a[2]+'<br>');
a[2] = a[2]*2;
document.write('The Array is : '+a+'<br>');
a[4] = 'New Value';
37
document.write('The Array is : '+a+'<br>');
var b = new Array();
b[0] = 100;
b[1] = 200;
b[2] = 300;
b[3] = 400;
b['Name'] = 'Rajesh';
b['Age'] = 30;
b[7] = 700;
b[10] = 1000;
document.write('<hr>Single string Index : '+b['Name']+'<hr>');
document.write('The Array is : '+b+'<br>');
for(i=0;i<b.length;i++){
document.write('Index at : '+i+' = '+b[i]+'<br>');
}
document.write('<hr>');
for(c in b){
document.write(c+' = '+b[c]+'<br>');
}
document.write('<hr>');
var d = [10,20,30];
document.write('The Array in d is : '+d+'<br>');
document.write('The Array in d is : '+d.length+'<br>');
document.write('<hr>');
38
var e = {'Name':'Rajesh','Age':30,10:20,'Status':'Active'};
document.write('The Array in d is : '+e+'<br>');
for(i=0;i<e.length;i++){
document.write('Index at : '+i+' = '+e[i]+'<br>');
}
for(c in e){
document.write(c+' = '+e[c]+'<br>');
}
</script>
Double dimensional array:
An array can have more than one array is called double dimensional
array.
Ex : douledimensionarray.html
<html>
<head>
<script>
var a =
[[1,'Ajay',[45,62,49,72,55,84]],[2,'Rajesh',[48,62,94,72,38,62]],[3,'Sur
esh',[48,63,82,97,45,28]]];
//document.write(a[1][1]);
document.write('Name is : '+a[2][1]);
document.write("<table border='1' align='center' width='60%' >");
document.write("<tr><th colspan='9'>Student Marks Memo Report
</th> ");
39
document.write("<tr><td rowspan='2'>Roll No</td> <td
rowspan='2'>Name</td><td colspan='6'
align='center'>Subjects</td><td rowspan='2'>Pass/Fail</td></tr>");
document.write("<tr><td>English</td><td>Hindi</td><td>Telugu
</td> <td>Maths</td><td>Science</td><td>Social</td></tr>");
document.write("<tr><td>"+a[0][0]+"</td></tr>");
</script>
</head>
<body>
<tr><td><script>document.write(a[1][0]);</script></td><td><script>
document.write(a[1][1]);</script></td></tr>
</table>
</body>
</html>
Array built-in Functions :
Join : Join is the pre-defined key-word in the JavaScript .which will
convert the given array into the separator passed default separator is
coma (,).
Concat : concat is joining more than array in single array is called
concat.
Reverse : reverse in JavaScript the array last being is first. First is
last without (descending order) the original array will also get
affected. If we use reverse function.
Sort : sort is nothing but given the order is ascending order .
Unshift : unshift will add the value at the starting of the array. The
variable use for unshift will holds the length of the array and the
original array would get affected.
40
Shift : shift function will not hold any arguments should will remove
the starting value of the array.The variable unshift will hold the
removed value.
Push : push is nothing but insert the value into the array at the end of
array is called push.
Pop : pop is nothing but remove the last value in the array is called
the pop.
Ex : arraybuiltin.html
<script>
var a = new Array('This','is','my','new','car');
document.write('The Original Array is : '+a+'<br>');
b = a.join(' ');
document.write('Join Method : '+b+'<br>');
var a = new Array(10,20,30);
var b = new Array(40,50);
var c = new Array(60,70,80);
document.write("Concat Two Arrays : "+a.concat(b)+"<br>");
document.write("Concat All Given Array : "+a.concat(b.concat(c))+"
<br>");
var a = new Array('Ajay','Raju','Amith','Zebra','Arjun');
b = a.reverse();
document.write("Reverse of an Array : "+b+'<br>');
document.write("Original Array : "+a+'<br>');
var a = new Array('Ajay','Raju','Amith','Zebra','Arjun');
b = a.sort();
document.write("Assending Order : "+b+'<br>');
41
document.write("Original Array : "+a+'<br>');
b = a.reverse();
document.write("Reverse With Desending Order : "+b+'<br>');
document.write("Original Array : "+a+'<br>');
var x = new Array(10,20,30);
b = x.unshift(5);
document.write("Unshift Method : "+x+'<br>');
document.write("The Value Stored in B : "+b+'<br>');
var x = new Array(5,10,20,30);
b = x.shift();
document.write("shift Method : "+x+'<br>');
document.write("Removed Value is stored B : "+b+'<br>');
var x = new Array(5,10,20,30);
b = x.push(40);
document.write("Push last Value to Array Method : "+x+'<br>');
document.write("B holds the length of the Array: "+b+'<br>');
var x = new Array(5,10,20,30);
b = x.pop();
document.write("Pop Removes last Value in Array : "+x+'<br>');
document.write("B holds the Removed Value: "+b+'<br>');
</script>
Functions:-
Functions in javascript are case sensitive once declare a function
name and try to re-declare. The same function name will overwrite
previous function name. Functions are used to debug the code and
42
analize the errors easily. Working with length of the code will be
reduced.
We have mainly 4 types of the functions in JavaScript that is
1. Function without arguments and return value
2. Function with arguments and no return value
3. Function with return value and no arguments
4. Function with arguments and return value
Syntax :
Function function name (arguments, arg)
{
//code
}
1. Function without arguments and return value
Ex :
<script>
test();
function test(){
document.write('This is Function without Aurgument<br>');
document.write('This is my function Content<br>');
}
function test1(){
document.write('Overwritten is done on the previous printing
methods<br>');
}
test();
43
test();
</script>
<body>
<script>
test();
</script>
</body>
2. Function with arguments and no return value
Ex :
<style>
.error{background:gold;color:green;padding:10px;margin:auto;width:
60%;font-size:18pt;}
.success{background:black;color:#fff;padding:10px;margin:auto;widt
h:60%;font-size:18pt;}
</style>
<script>
function welcome(name){
document.write("Welcome ! "+name+'<br>');
}
welcome('Rajesh');
welcome('Amith');
function statement(type,message){
document.write("<div class='"+type+"'>"+message+"</div>");
}
//statement("error","Welcome Guest ! ");
44
statement("success","Welcome Rajesh");
</script>
3. Function with return value and no arguments
Ex :
<script>
function test(){
document.write('This is line 01<br>');
document.write('This is line 01<br>');
return 10 2;
document.write('This is line 01<br>');
document.write('This is line 01<br>');
}
test();
var x = test();
document.write('The Value in x is : '+x+'<br>');
</script>
4. Function with arguments and return value
Ex :
<script>
function square(num){
return num*num;
}
document.write('The Square root of 5 is : '+square(5)+'<br>');
document.write('The Square root of 5 is : '+square(square(5))+'<br>');
45
</script>
Math built-in function :
In JavaScript we have mainly seven kinds of math objects which are
pre-defined and can be called respective key-words. Which are
included in JavaScript library.
Ex : math.html
<script>
function r(txt){
document.write('<h2>'+txt+'</h2>')
}
r("<u>Javascript Predefined Math Constant Object </u>");
r('Eulers Constant : '+Math.E);
r('Pi Value : '+Math.PI);
r('SQRT OF 2 : '+Math.SQRT2);
r('Natural Log 2: '+Math.LN2);
r('Natural Log 10 : '+Math.LN10);
r('Log base 2 of Eulers : '+Math.LOG2E);
r('Log base 10 of Eulers : '+Math.LOG10E);
r("<u>Javascript User - defined Math Object </u>");
r('Max Value : '+Math.max(10,20,30));
r('Min Value : '+Math.min(10,20,30));
r('Sqrt Value : '+Math.sqrt(25));
r('2 pow 4 : '+Math.pow(2,4));
r('Absolute Value : '+Math.abs(-9));
46
r('Ceil Value : '+Math.ceil(2.11111));
r('floor Value : '+Math.floor(2.9999));
r('round Value : '+Math.round(2.5111111));
r('Random Number : '+Math.random());
r('Number Between 1 to 1000 : '+Math.round(Math.random()*1000));
</script>
String built-in functions :
Ex : stringbuilt.html
<script>
function r(txt){
document.write(txt+'<br>');
}
var str = "lamp Institute";
r('String Value = '+str);
r("Length of the String = "+str.length);
r("Color of String = "+str.fontcolor('green'));
r('Upper Case = '+str.toUpperCase());
r('Lower Case = '+str.toLowerCase());
r('Big Font = '+str.big());
r('Bold Font = '+str.bold());
r('Small Font = '+str.small());
r('Italic Font = '+str.italics());
r('Superscript = '+str.sup());
r('sub script = '+str.sub());
47
r('<hr><h2><u>Slice Function([begin, stop]) </u></h2>');
r('Slice(4) = '+str.slice(4));
r('Slice(4,8) = '+str.slice(4,8));
r('Slice(-9) = '+str.slice(-9));
r('Slice(-9,8) = '+str.slice(-9,8));
r('Slice(-9,-3) = '+str.slice(-9,-3));
r('<hr><h2><u>Substring Function([From, to]) </u></h2>');
r('substring(4) = '+str.substring(4));
r('substring(4,8) = '+str.substring(4,8));
r('substring(4,2) = '+str.substring(4,2));
//r('substring(-9) = '+str.substring(-9));
r('<hr><h2><u>substr([start, length]) </u></h2>');
r('substr(4) = '+str.substr(4));
r('substr(5,8) = '+str.substr(5,8));
r('substr(-9) = '+str.substr(-9));
r('substr(-9,2) = '+str.substr(-9,1));
r('CharAt(0) = '+str.charAt(1));
r('charCodeAt(1) = '+str.charCodeAt(1)); //ascill Value of Index
mob = 'Z123456789';
r('charCodeAt = '+mob.charCodeAt(0));
r('Indexof = '+str.indexOf('T'));//-1
r('lastIndexof = '+str.lastIndexOf('t'));
r('indexOf = '+str.indexOf('t',9));
r('Search = '+str.search('z'));//-1
48
r('Match = '+str.match('z'));//null
</script>
Mobile function :
Ex : mob.html
<script>
function r(txt){
document.write(txt+'<br>');
}
mob = "8855644045";
r(isValidMobile(mob));
function isValidMobile(val){
if(val.length != 10){
return "Please Enter 10-Digit Mobile Number";
}
f = val.charAt(0);
if(f == '7' || f == '8' || f == '9'){
} else {
return 'Please Check the First Digit of Number & try
Again';
}
return isNumeric(val);
}
function isNumeric(val){
for(i=0;i<val.length;i++){
49
ascii = val.charCodeAt(i);
if(ascii < 48 || ascii >57){
return 'Only Numbers Allowed Please Check again';
}
}
return 'Valid Mobile Number';
}
</script>
Date functions: -
Date function can be defined with variable is equal to new date. This
function is pre-defined in JavaScript which will explain the system
timing (or) running the domain it will capture the running domain.
Get time () : This is unique time constant which is created find
generate number of milliseconds right from night jan 1st 1970.
Ex : date.html
<script>
function r(txt){
document.write(txt+'<br>');
}
var d = new Date();
r('The value in d is : '+d);
r('Unix Time Constant that is Midnight Jan 01,1970 (no of
millseconds : ) '+d.getTime());
r('Date : '+d.getDate());
r('Day : '+d.getDay());
50
r('Month : '+(d.getMonth()+1));// 0 -11
r('Year : '+d.getYear());//works only in ie...
r('FullYear : '+d.getFullYear());
r('Hours : '+d.getHours());
r('Minutes : '+d.getMinutes());
r('Seconds : '+d.getSeconds());
r('Time is : '+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds());
</script>
DOM :
DOM contains these layers
1.IMAGES
2.LOCATIONS
3.SCREEN------------------> Get Element ById
4.DOCUMENTS-----------> GetElementByTagName
5.NAVIGATOR------------ > GetElementByName
6.EMBED
Ex : dom.html
<script>
function dochange(){
document.testForm.fname.value = alert("Please Enter");
document.testForm.fname.value = 'Enter Name';
document.testForm.lname.style.border="2px solid red";
document.testForm.lname.style.width="200px";
}
51
</script>
<body>
<form name='testForm'>
First Name : <input type='text' name='fname' /><br>
Last Name : <input type='text' name='lname'/><br>
<input type='button' name='change' value='DoChange'
onclick="javascript:dochange();"/>
</form>
</body>
Get Element ById :
This particular function will match the id of the element and that
particular matching function will get executed
Ex : getElementById.html
<script>
function dochange(){
var x = document.getElementById('test').value;
document.getElementById('test').value = x.toUpperCase();
document.getElementById('test').style.color = 'red';
}
</script>
<body>
<form name='testForm'>
First Name : <input type='text' name='fname' id='test'
onblur="dochange();"/><br>
First Name : <input type='text' name='lname' id='fldtest'
onkeyup="dochange();"/>
52
</form>
</body>
GetElementByTagName :
This particular function will match tag name and excute the function
which we are passing as a tag name
Ex : getElementsByTagName.html
<script>
function dochange(){
var a = document.getElementsByTagName('div');
for(i=0;i<a.length;i++){
a[i].style.width = '400px';
a[i].style.background = '#ddd';
a[i].style.border = '4px dotted green';
}
}
</script>
<body onmouseover='dochange();'>
<h1>Welcome to My Web Page</h1>
<p>This is my First Page</p>
<p>This is my First Page</p>
<p>This is my First Page</p>
<p>This is my First Page</p>
<div>What is Social Hub</div>
</body>
53
GetElementByName :
This particular function will match element name and that part of the
function will get excutes.
Ex : getElementsByName.html
<script>
function dochange(){
var a = document.getElementsByName('x');
for(i=0;i<a.length;i++){
a[i].style.width = '400px';
a[i].style.background = '#ddd';
a[i].style.border = '4px dotted green';
}
}
</script>
<body onmouseover='dochange();'>
<h1>Welcome to My Web Page</h1>
<p>This is my First Page</p>
<p>This is my First Page</p>
<p>This is my First Page</p>
<p>This is my First Page</p>
<div>What is Social Hub</div>
</body>
Note 1 : As ids are unique we have singular matching so we can
getElementById as singular.
54
Note 2 : GetElementByTagName & ByName works the array format
and these are plural.
Events :
Whenever an event is trigger and then that particular matching
function will excuted.
a)innerHTML : innerHTML is used to push the dynamic values on
to the HTML page.
b)set Interval : setInterval is pre-defined key-word in JavaScript
which takes 2 arguments the first argument can be expression (or)
function the second argument can be number of milliseconds.
c)Alert : Alert gives you a single button option until it is click It will
allowed you to navigate on the server.
Ex : alert.html
<script>
alert("Please Agree with Our Terms & condition");
</script>
<body>
Welcome
</body>
d)Confirm : Confirm is used two options until something is being
click. It won’t allowed to navigate the server and if it is click based on
the values it will moved to the respect pages.
Ex : confirm.html
<script>
var x = confirm("Are You legally 18+ then enter to site");
if(x == true){
document.write("Welcome to my Terrorist Site");
55
} else {
document.write("Thank You for leaving Please <a
href='http://www.google.com'>Click Here</a>");
}
</script>
<body>
</body>
e)Eval : Eval is pre-defined function in JavaScript which will
evaluate the given function in between the JavaScript (function)
f)parseINT : This is pre-defined function in JavaScript which will
convert the floating value into integer value.
g)parseFLOOT : This is pre-defined function in JavaScript which
will convert the integer value into floating value.
Ex : innerHTML & set Interval time.html
<script>
function r(txt){
document.write(txt+'<br>');
}
function currTime(){
var d = new Date();
var time =
timeFormat(d.getHours())+':'+timeFormat(d.getMinutes())+':'+timeFo
rmat(d.getSeconds());
return 'Present Time : '+time;
}
function timeFormat(val){
return ((val<10)?'0':'')+val;
56
}
function writeTime(id){
return document.getElementById(id).innerHTML = currTime();
}
</script>
<body>
<div id='currentTime' align='right'>
<script>
r(currTime());
setInterval("writeTime('currentTime')",1000);
</script>
</div>
</body>
57
58
PHP
 Rasmus Lerdorf is the founder of the PHP in 1995.
 PHP is the server side scripting language.
 Php needs a server to excute the file.
 Php files should be saved with .php as its extension ".php3", or
".phtml"
 Or else our server will not excute unknown extension apart from
.html, .cpi, .cgs,
 Php supports all the data bases that are present in the market
Ex:-mySql,mssql,infonix,Sybase,ibmdb2,postgresql………etc
 Php can be worked on all the operating systems that is
windows,linux,max,solaries…etc
 Php can communicate with different servers
Ex:-SMTP(Simple mail transfer protocal), imap (internet max
access protocal), LDAP, Informix, Oracle, Sybase, Solid,
PostgreSQL
 PHP can be install as a software tags we get many of the server
files
Ex : Xampp, Wamp, easy php, mamp
 PHP stands for PHP: Hypertext Preprocessor
 PHP is an open source software
 PHP is free to download and use
 PHP is easy to learn and runs efficiently on the server side
Xampp : Xampp stands for
x------------------------>platform(windows,linux,mac,solaries)
a------------------------->apache(web server)
m------------------------>mysql(database file)
p------------------------->perl(perl scripting in php)
p------------------------->php/my admin (web database tool)
php current version is 5.3.8
59
Wamp : Wamp stands for
w------------------------>window exv
a------------------------>apache(web server)
m------------------------>mysql(database file)
p------------------------>php/my admin (web database tool)
Mamp : Mamp stands for
m------------------------>mac ‘os’
a------------------------->apache(web server)
m------------------------>mysql(database file)
p------------------------->php/my admin (web database tool)
Apache contain the 1-65535 ports.In that 1-1024 are pre-reserved
ports.
Tmp : Tmp holds session details & temp upload files.
Htdocs : After installing xampp we have to store our files into the
folder called htdocs. Once files are saved in htdocs we can open with
the location path as
http://localhost/abc(foldername)/first.php
Echo : echo is the output method in php.
Basic PHP Syntax :
<?php
echo “universal way of writing php<br>”;
?>
<script language = ‘php’>
60
echo “javascript way of writtting php<br>”;
</script>
<?
echo”short tag way of writing php<br>”;
?>
<%
1echo “asp way of writing php<br>”;
%>
Comments in PHP :
In PHP, we use // to make a one-line comment or
/* and */ to make a comment block
<html>
<body>
<?php
//This is a comment
/*
This is
a comment
block
*/
?>
</body>
</html>
61
Printing methods in php :
a.Echo : echo is an argument can print multiple arguments. Echo as a
function can print only one argument.
b.Print : print is an argument can print only one argument.print also a
function
Ex: - print”arg<br>”;
c.Printf : printf will take formatting string with respected values as
print
Ex : printf(“(int%d) (float%f) (string %s) (asci%c)”);
d.Print-r : print-r will print array of string
Ex: - $g = array (10,20,30,true,’kalam’);
Print-r($g);
e.Var-dump : It is also printing method which is used debugging the
errors very easily. This not used in production level (live
environmental )
Ex : var-dump($g);
<h1>Printing Methods in PHP</h1>
<?php
$a = 10; $b = 20; $c = 30;
echo "Arg01","Arg02","Arg03<br>";
echo $a,$b,$c,'<br>';
echo ("Arg01<hr>");
print "Arg01<br>";
print("Arg01<hr>");
62
printf("(int %d) (float%.2f) (string %s) (Ascii %c)
",22.25,10.2545,'Rajesh',97);
echo '<hr>';
$g = array(10,20,30,true,'Rajesh');
print_r($g);
echo '<hr>';
var_dump($g);
?>
Controlling :
Ex : controlling.php
<style>
b{color:green;}
</style>
<?php
echo "line 01<br>";
echo "line 02<br>";
echo "line 03<br>";
?>
<b>This is Bold Tag</b><hr>
<?php
if(false){
echo "<b>The 1<sup>st</sup> is Executed<br></b>";
} else {
echo "<b>The 2<sup>nd</sup> is Executed<br></b>";
63
}
?>
<hr>
<h2>Alternate Method</h2>
<?php
if(true){
?>
<b>The 1<sup>st</sup> is Executed<br></b>
<?php
}
else
{
?>
<b> The 2<sup>nd</sup> is Executed<br></b>
<?php
}
?>
Variables :
 Variables are "containers" for storing information.
 Variables in PHP starts with a $ sign, followed by the name of
the variable.
 The variable name must begin with a letter or the underscore
character.
 A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _).
 A variable name should not contain spaces.
64
 Variable names are case sensitive (y and Y are two different
variables).
Ex : variables.php
<h1>Variables in php</h1>
<?php
$a = 10;
$name = 'Rajesh';
$_name
$_name
$n123
$_1232
$1_name
$first_Name
echo 'The Value is : ',$a.'<br>';
echo 'The Name is : ',$name,'<br>';
?>
<script>
var a = 15;
document.write('The Value of a is : '+a+'<br>');
</script>
 In PHP, a variable does not need to be declared before adding a
value to it.
65
 In the example above, notice that we did not have to tell PHP
which data type the variable is.
 PHP automatically converts the variable to the correct data type,
depending on its value.
 In a strongly typed programming language, you have to declare
(define) the type and name of the variable before using it.
PHP has four different variable
 local
 global
 static
 Super global array variable
Local variable : A variable declared within a PHP function is local
and can only be accessed within that function.
Ex : localvariable.php
<?php
function test(){
$a = 10;
echo 'The Value of $a inside function is : ',$a,'<br>';
}
test();
echo 'The Value of $a Outside Function is : ',$a,'<br>';
?>
Static variable : When a function is completed, all of its variables
are normally deleted. However, sometimes you want a local variable
not to be deleted.
To do this, use the static keyword when you first declare the variable.
66
Ex : staticvariable.php
<?php
function test(){
$a = 10;
static $b = 20;
echo 'The Value of $a inside function is : ',$a,'<br>';
echo 'The Value of $a inside function is : ',$b,'<br>';
$a++;
$b++;
}
echo 'The Value of $b outside is : ',$z,'<br>';
test();
test();
?>
Global variable : Global scope refers to any variable that is defined
outside of any function.
Global variables can be accessed from any part of the script that is not
inside a function.
To access a global variable from within a function, use the global
keyword:
Ex : global.php
<?php
$x = 10;
67
echo 'The Value of $x = ',$x,'<br>';
function test(){
//global $x;
echo 'The Value of $x inside Function = ',$x,'<br>';
echo '$GLOBALS["x"] = ',$GLOBALS['x'],'<br>';
}
test();
?>
Super global array variable : ‘$ global’ is the super global array
variable. This is the pre-defined keyword. In php we have mainly
some of the super global variables. This can be used with their
keywords.
i) $_EVN : This is used for getting the information of your operating
system ($_ENV (PATH))
ii) $_SERVER : This will give you the information about your
server(apache information)
iii) $_GET : It is used for form processing through get method (or)
query string
iv) $_POST : This is used for form processing through post method
in secure manner
v) $_REQUEST : It will send the form through both get and post and
cookie
vi)$_COOKIE : This is used to get the information about the browser
who is using the web(computer)
vii)$_SESSION : It is used to get the information of the user in
between login and logout details are store at server machine.
68
Operators :
1. Assignment operator: = is used to assign values to variables in
PHP
2. Arithmetic operator: +,-,/,*,%
3. Increment & decrement operator: i++,++I & i--, --i
4. Comparison operator: ==,!= ,===
5. Relational operator: <=, >=, <>
6. Logical operator: &&, ||, and, or
7. Error handling operator :
8. Scope resolution & this operator : ::----->scope, &------->this
Ex : operator.php
<?php
echo '<h1 align="center">Assignment Operator</h1>';
$a = 10;
echo 'The Value is : '.$a.'<br>';
echo 'The Value is Added by 2 : ',$a += 2,'<br>';
$name = 'Rajesh';
echo 'My name is : '.$name,'<br>';
$name .= ' Kumar';
$name = $name.' Kumar';
69
echo 'My name is : ',$name,'<br>';
echo '<h1 align="center">Arthamatic Operator</h1>';
echo 'The value of 2+3 : ',2+3,'<br>';
echo 'The Value of 2-3 : ',2-3,'<br>';
echo 'The Value of 2/3 : ',2/3,'<br>';
echo 'The Value of 2*3 : ',2*3,'<br>';
echo 'The Value of 2%3 : ',2%3,'<br>';
echo '<h1 align="center">Increment & Decrement [INC/DEC]</h1>';
echo '<h2>POST & PRE increment</h2>';
$x = 10;
echo 'The Value of $x = ',$x,'<br>';
echo 'The Value of $x++ = ',$x++,'<br>';
echo 'The Value of $x = ',$x,'<br>';
echo 'The Value of ++$x = ',++$x,'<br>';
echo 'The Value of $x = ',$x,'<br>';
echo '<h2>POST & PRE Decrement</h2>';
echo 'The Value of $x-- = ',$x--,'<br>';
echo 'The Value of $x = ',$x,'<br>';
echo 'The Value of --$x = ',--$x,'<br>';
echo 'The Value of $x = ',$x,'<br>';
echo '<h1 align="center">Comparision Operator</h1>';
70
var_dump(10 == 10);echo'<br>';
var_dump(10 != '10');echo'<br>';
echo '<h1 align="center">Relational Operator</h1>';
var_dump(10<=10);echo '<br>';
var_dump(10<>'10');echo '<br>';//not Equal to
echo '<h1 align="center">logical Operator</h1>';
var_dump(true && true);echo '<br>';
var_dump(true && false);echo '<br>';
var_dump(true || true);echo '<br>';
var_dump(true || false);echo '<br>';
var_dump(false AND FALSE);echo '<br>';
var_dump(false OR FALSE);echo '<br>';
echo '<h1 align="center">Error Handling Operator</h1>';
echo @sqrt();
//@test();
echo 'Some Data';
echo '<h1 align="center">Scope Resolution & this Operator {:: & -
>(this)}</h1>';
class A{
static $z = 100;
public $a = 20;
public $k = 50;
71
protected $b = 30;
private $c = 40;
function test(){
echo "A Test Function called inside Class A";
}
}
$obj = new A;
echo $obj->a,'<br>';
echo $obj->k,'<br>';
//echo $obj->b,'<br>';
//echo $obj->c,'<br>';
echo ' The Static Value is : ',A::$z,'<br>';
echo 'The Function inside Class is : ',$obj->test(),'<br>';
?>
Type Casting: -
Conversion of the one data type into another data type is known as
type casting. in php we have mainly two types of costing
1. Temporary type casting
2. Permanent type casting
1. Temporary type casting : Casting which can be done for single
step by pre-defined the data type keyword. That particular variable
will hold Temporary type casting.
72
Ex : temporary.php
<?php
$x = "10.254Kgs";
var_dump($x);echo "<br>";
var_dump((int)$x); echo "<br>";
var_dump($x); echo '<br>';
var_dump((float)$x); echo '<br>';
var_dump((boolean)$x);echo'<br>';
var_dump((string)$x);echo "<br>";
var_dump($x);echo "<br>";
var_dump(floatval($x)); echo '<br>';
var_dump(intval($x)); echo '<br>';
var_dump($x);echo "<br>";
?>
2. Permanent type casting : This can be done by using pre-defined
key-word set type.which hold two arguments
Syntax : set type (var name,’int’);
Ex : Permanent type casting.php
<?php
echo '<h1>Permanent Type Casting</h1>';
$x = "10.254Kgs";
73
settype($x,'float');
var_dump($x);echo "<br>";
settype($x,'int');
var_dump($x);echo "<br>";
settype($x,'boolean');
var_dump($x);echo "<br>";
settype($x,'int');
var_dump($x);echo "<br>";
var_dump($x);echo "<br>";
settype($x,'float');
var_dump($x);echo "<br>";
?>
Type juggling : conversion of data types by using expression to
another data types are known as type juggling.
Ex : typejuggling.php
<?php
echo 'true + true : ',true+true,'<br>';
if(null){
echo "Printed";
} else {
echo "Not Printed";
74
}
?>
Variable validation function :
i) Isset : Isset of variables will check with the variable initialize or
not and return Boolean
ii) empty(var name) : empty function will check the variable
whether it is null or not and return Boolean
iii) Unset (var name) : This function will remove the variable (or)
delete the variable
iv) get type(var name) : This function will let us know the argument
data type in the form of string ,this should be used because the
coming variable would be depreciated.
Ex : variable_validation.php
<?php
$x = 10;
var_dump($x);echo '<br>';
var_dump(isset($x));
var_dump(isset($a));echo '<hr>';
$z = '';
var_dump(empty($z));
var_dump(empty($y));
$k = 10;echo '<br>';
var_dump(gettype($k));
75
unset($x);
var_dump(isset($x));
?>
Data Types :
Php supports mainly 8 kinds of data types among which four are
stable data types, two are compound data types and another two are
special data types
a)Stable data types :
i) int (or) integer
ii) Float (or) real (or) decimal
iii) Boolean data types
iv) string data types
i)int (or) integer : All non decimal values . range in between 2(32-1)
to -2(32-1)
Ex :
<?php
echo "<h1 align='center'>Stable Data types</h1>";
echo "<h2>Integer Data Type</h2>";
$x = 10;
var_dump($x);echo '<br>';
$x = (pow(2,32-1)-1);
var_dump($x); echo '<br>';
76
$judge = 2147483647;
var_dump($judge);
?>
ii) Float (or) real (or) decimal : All decimal values. Range in
between 10(38) to 10(-38)
Ex :
<?php
echo "<h2>Float Data Type</h2>";
$a = 10.25;
var_dump($a);echo '<br>';
?>
iii) Boolean data types : Boolean data types return the values in the
form of true (or) false
Ex :
<?php
echo "<h2>Boolean Data Type</h2>";
$a = false;
var_dump($a);
?>
iv) String data types : Collection of characters enclose in between
single (or) double cotations are known as string data types.
77
Ex :
<?php
echo "<h2>String Data Type</h2>";
$x = 10;
echo '<br>The Value of $x is ',$x,'<br>';
echo "The Value of $x is :$x";
$name = "Rajesh";
echo '<br>my name is $name <br>';
echo "my name is $name <br>";
$x = 10;
$y = 20;
echo 'The value of $x+$y = ',$x+$y,'<br>';
echo "The value of $x+$y = ",$x+$y,'<br>';
?>
b)Compound data types :
Compound data types again two types
1. Array data type
2. Object data type
1. Array data type : Array data type which can hold more than one
value. In php we have mainly 3 kinds of arrays
i) Numerical array
ii) Associative array
78
iii) Mixed array
Declaring an array in php can be done by two types
 array as the function
 array as a square bracket
i) Numerical array :
A numeric array stores each array element with a numeric index.
There are two methods to create a numeric array.
 In the following example the index are automatically assigned
(the index starts at 0):
$cars=array("Saab","Volvo","BMW","Toyota");
 In the following example we assign the index manually:
$cars[0]="Saab";
$cars[1]="Volvo";
$cars[2]="BMW";
$cars[3]="Toyota";
Ex :
<?php
$cars[0]="Saab";
$cars[1]="Volvo";
$cars[2]="BMW";
$cars[3]="Toyota";
echo $cars[0] . " and " . $cars[1] . " are Swedish cars.";
?>
ii) Associative array :
An associative array, each ID key is associated with a value.
79
When storing data about specific named values, a numerical array is
not always the best way to do it.
With associative arrays we can use the values as keys and assign
values to them.
Example 1
In this example we use an array to assign ages to the different
persons:
$ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);
Example 2
This example is the same as example 1, but shows a different way of
creating the array:
$ages['Peter'] = "32";
$ages['Quagmire'] = "30";
$ages['Joe'] = "34";
The ID keys can be used in a script:
<?php
$ages['Peter'] = "32";
$ages['Quagmire'] = "30";
$ages['Joe'] = "34";
echo "Peter is " . $ages['Peter'] . " years old.";
?>
The code above will output:
Peter is 32 years old.
iii) Mixed array :
Mixed array is nothing but combination of numerical & associative
array is known as mixed array.
80
Ex : mixedarrays.php
<?php
$a = array("Name"=>"Rajesh","Age"=>30);
print_r($a);
echo '<hr>';
echo '<h1 align="center">Mixed Arrays</h1>';
define('A','ABC');
define('B','XYZ');
$c = 10;
$d = 20;
$g =
array(0=>10,1=>20,'Name'=>'Raj','Age'=>30,5=>500,5.55=>600,-
9=>'Negative value',true=>200,false=>200,''=>'Empty
Value',NULL=>'Null Value',A=>B,$c=>$d);
echo '<pre>';
print_r($g);
echo '</pre>';
?>
2. Object data type :
Object is an instance of class.Class can be denoted with in class name.
Collection of variables and functions are known as class.For Calling
class we should create an object then that particular variable is
known as object variable.
81
Ex :
<?php
echo "<h2>Object Data Type</h2>";
class A{
public $x = 10;
public $a = 20;
function test(){
echo 'A test Function called<br>';
}
}
$b = new A;
var_dump($b);
echo '<br>Public Value $x = ',$b->x,$b->test(),'<br>';
?>
Special data types :
Special data types are again two types
i) Resource data types
ii) Null data types
i) Resource data types : Resource data type is calling an external
variable value into another variable using (&) resource variable.
82
ii) Null data types : This is the pre-defined key-word. When a
variable not initialize and by asking through printing method. This
will result in null value.
Ex :
<?php
echo "<h1 align='center'>Special Data types</h1>";
echo "<h2>Reference Data Type</h2>";
$x = 10;
$y = $x;
echo 'The Value of $x = ',$x,'<br>The Value of $y = ',$y,'<br>';
$x = 12;
echo 'The Value of $x = ',$x,'<br>The Value of $y = ',$y,'<br>';
$y = 'Rajesh';
echo 'The Value of $x = ',$x,'<br>The Value of $y = ',$y,'<hr>';
echo "<h2>Resourse Data Type</h2>";
$a = 10;
$b = &$a;
echo 'The Value of $a = ',$a,'<br>The Value of $b = ',$b,'<br>';
$a = 'Raj';
echo 'The Value of $a = ',$a,'<br>The Value of $b = ',$b,'<br>';
$b = 'Amith';
echo 'The Value of $a = ',$a,'<br>The Value of $b = ',$b,'<br>';
83
echo "<h2>Null Data Type</h2>";
var_dump($z);
?>
Constant :
Define : Define is the pre-defined key-word in php. This will take
two arguments. The first argument being the constant identifier which
identifier its second argument value. We can pass third argument as
Boolean to make case in-sensitive
Ex : constant.php
<?php
define('x',10,true);
echo x,'<br>';
echo X;
echo '<hr>';
define('url','http://www.socialhub.com',true);
echo uRl,'/register.php';
echo '<hr>';
define('SITE_NAME','http://www.socialhub.in-hyderabad','Social
Hub');
?>
<h1>About us</h1>
we at <?php echo SITE_NAME;?> are in training ........
<h1>Contact Us</h1>
84
<?php echo SITE_NAME;?>
street ......
<h1>FAQ</h1>
what we do at <?php echo SITE_NAME;
?>
Conditions :
Conditional statements are used to perform different actions based on
different conditions
a)If condition :
IN PHP
IN PERL
If (cond)
if (cond) :
{
//code
//code
else if (code) :
}
//code
else if (cond)
else (cond) :
{
//code
//code
end else if ;
}
85
else (cond)
{
//code
}
b)Switch condition :
Syntax :
switch (cond) :
switch (cond):
{
|
Case1 :
|
//code
|
Break;
|
Case2:
//code
|
Break;
end switch;
|
|
Default:
//code
}
86
Ex :
<html>
<body>
<?php
$x=1;
switch ($x)
{
case 1:
echo "Number 1";
break;
case 2:
echo "Number 2";
break;
case 3:
echo "Number 3";
break;
default:
echo "No number between 1 and 3";
}
?>
</body>
</html>
c)While condition : The while loop executes a block of code while a
condition is true
Syntax:
While (cond)
while (cond):
{
//code inc/dec
//const code inc/dec
endwhile
}
87
Ex:
<html>
<body>
<?php
$i=1;
while($i<=5)
{
echo "The number is " . $i . "<br />";
$i++;
}
?>
</body>
</html>
d)Do-while condition : The do-while statement will always execute
the block of code once, it will then check the condition, and repeat the
loop while the condition is true.
Syntax :
Do do:
{ //code
Inc/dec
//code enddo
while(cond);
}
While (cond)
Example :
The example below defines a loop that starts with i=1. It will then
increment i with 1, and write some output. Then the condition is
checked, and the loop will continue to run as long as i is less than, or
equal to 5:
<html>
<body>
88
<?php
$i=1;
do
{
$i++;
echo "The number is " . $i . "<br />";
}
while ($i<=5);
?>
</body>
</html>
e)For loop : Loops execute a block of code a specified number of
times, or while a specified condition is true. The for loop is used when
you know in advance how many times the script should run.
Syntax :
For(initialize;cond;inc/dec)
//code
end for
Example :
The example below defines a loop that starts with i=1. The loop will
continue to run as long as i is less than, or equal to 5. i will increase
by 1 each time the loop runs:
<html>
<body>
<?php
for ($i=1; $i<=5; $i++)
{
echo "The number is " . $i . "<br />";
}
?>
</body>
</html>
89
f)for each : for each is usefull for all non-sequence data of an array.
Associative array ,numerical array object data of an array.
The general syntax is
foreach (arrayName as arr[value]))
{
echo arr [value];
}
Another syntax is
foreach (arrayname as key=>value)
{
echo key’-‘value (or) echo “key-value”;
}
Ex : foreach.php
<?php
$a = array("Name"=>"Rajesh","Age"=>30);
/*foreach(arrayname as value){
echo arr[value];
}*/
foreach($a as $v){
echo $v,'<br>';
}echo '<hr>';
/*foreach(arrayname as key=>value){
echo key,' - ',value;
}*/
foreach($a as $k=>$v){
90
echo "$k - $v<br>";
//echo $k,' - ',$v,'<br>';
}
?>
Functions :
Functions are case in-sensitive.Once function can be declare con’t be
re-declare in the program.
The real power of PHP comes from its functions.
In PHP, there are more than 700 built-in functions.
To keep the script from being executed when the page loads, you can
put it into a function.
A function will be executed by a call to the function.
You may call a function from anywhere within a page.
 Give the function a name that reflects what the function does
 The function name can start with a letter or underscore (not a
number)
Syntax:
function function name (arg)
{
//code
Return value
}
There are mainly 8 kinds of functions in php
91
1. Conditional Function : A function which is enclose inside
condition is considered as conditional function
Ex : conditional.php
<?php
if(false){
function test(){
echo "I am a Conditional Function <br>";
}
}
@test();
2. Variable Function : When a function name is told In variable.
Variable can be used for excuting the function in a place of function
name
Ex : variables.php
?php
function test(){
echo "I am a Variable Function <br>";
}
test();
$a = 'test';
echo $a;echo '<br>';
$a();
$a();
3. Function Function : Function is define inside another function is
called as function-function.
92
Ex : function's function.php
<?php
Function parent f(){
echo “iam write the function function<br>”;
If(!function_exists(childF))
{
function child F()
{
echo “I need some one to open parent file for me to excute<br>”;
}
}
}
Parent F();
Child F();
Parent F()’
?>
4. Function with arguments : Function can be defined with one (or)
more arguments. If arguments are not passed then it creates warning
in the program
Ex :
<?php
function test($x,$y){
echo 'The Value of $x = ',$x,'<br>';
echo 'The Value of $y = ',$y,'<br>';
}
93
test('Raj','Kiran');
test(10,20);
test('Amith');
test();
?>
5. default argument : A function at the time of a declaration if
argument are assign with some values they will be treated as optional
(or) default argument value and they can be passed with value (or)
can left without passing the value. Works at the side default argument
must be passing last in the program at the argument list
Ex :
<?php
function test($x=10,$y=20){
echo 'The Value of $x = ',$x,'<br>';
echo 'The Value of $y = ',$y,'<br>';
}
test(100,200);
test('Raj','Kiran');
test();
?>
6. Overloaded argument : A function can be define with argument
(or) that the defined arguments they are still acknowledge inside the
function using various pre-defined function
i) func_num_args() : return the total number of arguments which are
passed in the function
94
ii) func_get_args() : return the array with all the arguments with the
function
iii) func_get_args(position) : return the argument value at the
specified position
Ex :
<?php
function test(){
echo "<h1>Overloaded Concept</h1>";
echo 'The Overloaded Length = ',func_num_args(),'<br>';
print_r(func_get_args());
echo '<hr>';
for($i=0;$i<func_num_args();$i++){
echo 'Index at : ',$i,' - ',func_get_arg($i),'<br>';
}
echo '<hr><h1>For Each Method</h1>';
$y = func_get_args();
foreach($y as $k=>$v){
echo "$k => $v<br>";
}
}
test(10,20,'Rajesh');
7. Function with Return value : Return key-word can be stop the
execution of the function.Return key-word can optionally followed
with a value which is return variable.Whenever a function is valid
another one value con’t be passed after the return statement multiple
value con’t be club as array (or) object and con’t be return wherever a
function is called.
95
Ex :
<?php
function test(){
echo "This is Return Information<br>";
//return 10;
echo "I am second info<br>";
return = 82;
echo "I am second info<br>";
}
test();
$y = test();
echo $y;
//echo $y;
8. i) arguments passed by value : When an argument passed by
value any change for the value inside the function owned be reflected
in the variable outside the function
ii) Arguments passed by reference : When an argument passed by
resource and change for the inside with be refer to the variable outside
the function
Ex :
<?php
function test($x,&$y){
$x +=2;
$y +=10; // $y = $y+10;
echo 'The Value of $x = ',$x,'<br>';
96
echo 'The Value of $y = ',$y,'<br>';
}
$a = 5;
$b = 10;
echo '$a = ',$a,'<br>';//5
echo '$b = ',$b,'<br>';//10
test($a,$b);
echo '$a = ',$a,'<br>';//5
echo '$b = ',$b,'<br>';//10
?>
Built-in Functions :
a)Math Functions :
Ex :
<?php
echo 'Math Pi Value = ',M_PI,'<br>';
echo 'Math Pi Value = ',M_PI_2,'<br>';
echo 'Math Pi Value = ',M_PI_4,'<br>';
echo 'Eulers Constant = ',M_E,'<br>';
echo 'SQRT 2 = ',M_SQRT2,'<br>';
echo 'SQRT 2 = ',M_SQRT1_2,'<br>';
echo 'Log of 2 = ',log(2),'<br>';
echo 'Log base 10 of 2 = ',log10(2),'<br>';
echo 'Absolute Value = ',abs(-9),'<br>';
echo 'Exponent of 1 = ',exp(2),'<br>';
97
echo 'pi() = ',pi(),'<br>';
echo 'ceil value = ',ceil(2.1111),'<br>';
echo 'Floor Value = ',floor(2.9999),'<br>';
echo 'round = ',round(2.51458),'<br>';
echo 'round = ',round(2.51558,2),'<br>';
echo 'rad2deg(M_PI) = ',rad2deg(M_PI),'<br>';
echo 'rad2deg(M_PI) = ',rad2deg(M_PI_2),'<br>';
echo 'rad2deg(M_PI) = ',rad2deg(M_PI_4),'<br>';
echo 'deg2rad = ',deg2rad(180),'<br>';
echo 'sin 90 = ',sin(M_PI_2),'<br>';
echo 'tan 45 = ',tan(M_PI_4),'<br>';
echo 'hypot value = ',hypot(3,4),'<br>';
echo 'rand(min,max) = ',rand(100,1000),'<br>';
echo 'min value = ',min(10,20,30),'<br>';
echo 'max Value = ',max(2.999,2.998),'<br>';
?>
b)Date & Time Functions :
Date : date is the pre-defined constant in php. It will generate current
date according to the number of arguments passed.
Mktime : Which can have arguments (hr, min, sec, month, day, year)
unique time stamp.
Check date() : Let us known the validate in a year
j----> represents day of the month without leading zeros
l---->view letter represents of the day of the way
L---> whether it’s a leap year (or) not
98
W---> week number of year weeks starts from Monday
w----> numerical represents of day of the way 0 for Monday through
6 for Saturday
S---> English original safix for the day of the month two character ex:
-st ,nd, rd,th
F----> a full representation of the month such as January (or) March
M---> short representation of the month such as jan (or) mar
m---> numerical representation of the month with leading zero’s
means 0-12
n---> numerical representation of month without zero’s which is 1-12
d---> number of days given in a month 28 (or) 31
y---> two digits representation of a year
Y---> it is representation of the full year
Time : Number of milliseconds sec right from unique time stamp
a---> lowercase ante meridiem and post meridiem
A---> uppercase ante meridiem and post meridiem
B---> swatch internet time
g---> 12- hours format of an hour without leading zeros
G---> 24- hour format of an hour without leading zeros
h---> 12- hours format of an hour with leading zeros
H--->24- hours format of an hour with leading zeros
i---> minutes with leading zero’s
s---> seconds with leading zero’s
u---> microseconds (added in php 5.2.2)
99
Ex :
<?php
echo 'Time zone set to : ',@date_default_timezone_get(),'<br>';
date_default_timezone_set('America/Denver');
echo 'Time zone set to : ',@date_default_timezone_get(),'<br>';
echo 'Today Date : ',@date("M-dS-Y, h:i:s a"),'<br><hr>';
date_default_timezone_set('America/Los_Angeles');
echo 'Time zone set to : ',@date_default_timezone_get(),'<br>';
echo 'Today Date : ',@date("M-dS-Y, h:i:s a"),'<br><hr>';
date_default_timezone_set('Asia/Calcutta');
echo 'Time zone set to : ',@date_default_timezone_get(),'<br>';
echo 'Today Date : ',@date("M-dS-Y, h:i:s A"),'<br><hr>';
var_dump(checkdate(02,29,1975));
echo '<hr>No of milliseconds from Unix time Constant ',time(),'<br>';
echo '<hr>Feature Date & time <br>';
echo 'Event is on : ',(date("M-dS-Y, h:i:s
a",mktime(7,9,52,8,23,2012))),'<br><hr>';
echo date('Y');
?>
c)Array built-in Functions :
<?php
$a = array(10,20,30);
function r($arr,$func=''){
if(!empty($func)){
100
echo "<h2 align='center'><u>$func</u></h2>";
}
foreach($arr as $k=>$v){
echo "$k = $v<br>";
}
echo '<hr>';
}
echo 'Array count = ',count($a),'<br>';
echo 'Size of = ',sizeof($a),'<br>';
echo 'Sum of Array = ',array_sum($a),'<br>';
echo 'Product of Array = ',array_product($a),'<br>';
$a =
array('Name'=>'Rajesh','Age'=>30,'Status'=>'Active','Email'=>'Raj@g
mail.com','Gender'=>'Male');
r($a,'Normal Array');
$b = array_change_key_case($a,CASE_UPPER);
r($b,'Upper Case');
$b = array_change_key_case($a,CASE_LOWER);
r($b,'Lower Case');
$b = array_flip($a);
r($b,'Array Flip');
$b = array_change_key_case(array_flip($a),CASE_UPPER);
r($b,'Array Flip Values');
$a = array('Doctor','Fruit','Software');
$b = array('Patient','Orange','PHP');
101
r(array_combine($a,$b),'Array Combine');
$a =
array('Name'=>'Rajesh','Age'=>30,'Status'=>'Active','Email'=>'Raj@g
mail.com','Gender'=>'Male');
echo '<h2 align="center">Array Chunk</h2>';
$b = array_chunk($a,3);
echo '<pre>';
print_r($b);
echo '</pre>';
$a = array(10,20,30);
$b = array(10,20,40,50);
r(array_merge($a,$b),'Array Merge');
r(array_intersect($a,$b),'Array Intersect');
r(array_diff($a,$b),'Array Diff');
$a =
array('raj@gmail.com','amith@gmail.com','rohan@gmail.com','sumit
@gmail.com','raj@gmail.com');
r(array_unique($a),'Array Unique');
r(array_reverse($a),'Array Reverse');
$a = array(10,20,30);
array_unshift($a,5);
r($a,'Unshift Method');
array_shift($a);
r($a,'shift Method');
array_push($a,40);
r($a,'Push Method');
102
array_pop($a);
r($a,'Pop Method');
$ns = $ss = $as = $ks =
array('Name'=>'Rajesh','Age'=>30,'Status'=>'Active','Email'=>'Raj@g
mail.com','Gender'=>'Male');
r($ns,'Normal Array');
sort($ss);
r($ss,'Sorted Array');
rsort($ss);
r($ss,'Reverse Sort Array');
asort($as);
r($as,'Associative Sort Array');
arsort($as);
r($as,'Associative Reverse Sort Array');
ksort($ks);
r($ks,'Key Sort Method');
krsort($ks);
r($ks,'Key Sort Reverse Method');
echo "<h2 align='center'>array_key_exists , array_search ,
in_array</h2>";
$a =
array('Name'=>'Rajesh','Age'=>30,'Status'=>'Active','Email'=>'Raj@g
mail.com','Gender'=>'Male');
echo 'Do i have Email Feild :
',var_dump(array_key_exists('Gender',$a)),'<br>';
echo 'Do we have Value with some :
',var_dump(array_search(30,$a)),'<br>';
103
echo 'Do we have Value with some :
',var_dump(in_array('Male',$a)),'<br>';
$a =
array('Name'=>'Rajesh','Age'=>30,'Status'=>'Active','Email'=>'Raj@g
mail.com','Gender'=>'Male');
r(array_keys($a),'Array Keys Calling');
r(array_values($a),'Array Value Calling');
$str = 'Hey i am from India & my name is Praveen';
$b = explode(" ",$str);
//print_r($b);echo '<br>';
echo 'The Length of your total Words = ',count($b),'<br><hr>';
for($i=0;$i<count($b);$i++){
echo 'The index at ',$i,' = ',$b[$i],'<br>';
}
$a =
array('raj@gmail.com','amith@gmail.com','raju@gmail.com','suresh
@gmail.com','raj@gmail.com','amith@gmail.com','raju@gmail.com','
suresh@gmail.com');
print_r($a);
$b = implode(',',$a);
<br><br>
To : <input type='text' name='name' value='<?php echo $b;?>'
size='60'/>
<hr>
<?php
$a = array('born','child','teen','father','dead');
r($a,'Normal Array');
104
echo 'The Present Pointer is at : ',current($a),'<br>And the Key is at
',key($a),'<br>';
echo 'Next : ',next($a),'<br>';
echo 'The Present Pointer is at : ',current($a),'<br>And the Key is at
',key($a),'<br>';
echo 'Previous location : ',prev($a),'<br>';
echo 'The Present Pointer is at : ',current($a),'<br>And the Key is at
',key($a),'<br>';
echo 'End Value : ',end($a),'<br>';
echo 'The Present Pointer is at : ',current($a),'<br>And the Key is at
',key($a),'<br>';
echo 'The Present Pointer is at : ',current($a),'<br>And the Key is at
',key($a),'<br>';
echo 'Reset ',reset($a),'<br>';
echo 'The Present Pointer is at : ',current($a),'<br>And the Key is at
',key($a),'<hr>';
$a = array('Name'=>'Rajesh','Age'=>30);
r(Each($a),'Each Method');
r(Each($a),'Each Method');
$a = array('ram','processor','computer');
list($gb,$intel,$dell) = $a;
echo "$gb & $intel together makes $dell faster<br><hr>";
$str = "write some large text matter.";
echo $str,'<br><hr>';
echo '<h2>Wordwrap</h2>';
echo wordwrap($str,20,'<br>',true);
?>
105
d)String built-in Functions :
<?php
echo '<h2>';
$str = "lamp institute";
echo "Normal String = ",$str,'<br>';
echo "Length of String = ",strlen($str),'<br>';
echo "To Upper Case = ",strtoUpper($str),'<br>';
echo "To Lower Case = ",strtoLower($str),'<br>';
echo "Upper case First Word = ",ucfirst($str),'<br>';
echo "Upper case words = ",ucwords($str),'<br>';
echo 'Reverse = ',strrev($str),'<br>';
echo '<hr>';
echo 'Position of str = ',strpos($str,'t'),'<br>';
echo 'last Position of str = ',strrpos($str,'t'),'<br>';
echo 'Postion of str after t again = ',strpos($str,'t',9),'<br>';
echo 'Position insensitive = ',stripos($str,'lamp'),'<br>';
echo 'last position at t insensitive = ',strripos($str,'T'),'<br>';
echo 'strstr will extract the entire string : ',strstr($str,"In"),'<br>';
echo 'strstr will extract the entire string : ',stristr($str,"in"),'<br>';
$name = 'Rajesh Kumar';
echo "substr = ",substr($name,0),'<br>';
echo "substr = ",substr($name,7,4),'<br>';
echo "substr = ",substr($name,-5,-1),'<br>';
$url = 'http://www.google.com?status=active';
106
$url .= '&';
echo 'substr = ',substr($url,0,-1),'<br>';
echo 'replace = ',str_ireplace('lamp','Apache',$str),'<br>';
$a =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX
YZ0123456789';
echo str_shuffle($a),'<hr>';
echo substr(str_shuffle($a),0,12);
echo '<hr>';
$name = "O'henry";
echo $name,'<br>';
echo addslashes($name),'<br>';
echo stripslashes('O'henry'),'<br>';
echo strip_tags("<b><i>Hi i am not feeling well</i></b>");
echo '<hr>';echo '<h2>';
$pwd = 'computer';
echo 'Original Name : ',$pwd,'<br>';
echo '<h1 align="center">One Way Encrypt</h1>';
echo 'Encrypt with MD5 = ',md5($pwd),'<br>';//32 char value
echo 'Encrypt with MD5 strict = ',md5($pwd,true),'<br>';//16 bit
binary format
echo 'Encrypt with sha1 = ',sha1($pwd),'<br>';//40 char vlaue
echo 'Encrypt with sha1 strict= ',sha1($pwd,true),'<br>';//20 binary
vlaue
echo 'Crypt = ',crypt($pwd),'<br>';
echo 'crypt salt = ',crypt($pwd,'d4'),'<br>';
107
echo '<h1 align="center">Encrypt & Decrypt Method</h1>';
echo 'encrypt = ',base64_encode($pwd),'<br>';
echo 'decrypt = ',base64_decode('Y29tcHV0ZXI='),'<br>';
echo '<h1 align="center">Url Encode & Decode</h1>';
$url = 'http://www.lamp.com?status=success&id=7&pid=20';
echo 'Original url = ',$url,'<br>';
echo 'encode = ',urlencode($url),'<br>';
echo 'decode =
',urldecode('http%3A%2F%2Fwww.lamp.com%3Fstatus%3Dsuccess
%26id%3D7%26pid%3D20'),'<br><hr>';
echo '<pre>';
$name = " Rajesh ";
echo 'My name is :',$name,'<br>';
echo 'My name is :',rtrim($name),'<br>';
echo 'My name is :',ltrim($name),'<br>';
echo 'My name is :',trim($name),'<br>';
echo '</pre>';
?>
PATH :
FILE : The full path and filename of the file. If used inside an
include, always contains an absolute path with some links
LINE : The current line number of the file.
DIR : The directory of the file.
Realpath : Returns absolute pathname
Basename : Returns filename component of path
108
Ex :
<?php
echo "File Information : ",__FILE__,'<br>';
echo "Base Name : ",basename(__FILE__),'<br>';
echo "Directory Name : ",dirname(__FILE__),'<br>';
echo "Directory Name : ",__dir__,'<br>';
echo "real Path : ",realpath(__FILE__),'<br>';
//echo "real Path : ",realpath('../..'),'<br>';
echo "Line NO : ",__LINE__,'<br>';
echo '<hr>';
$a = pathinfo(__FILE__);
//print_r($a);
foreach($a as $k=>$v){
echo $k,' = ',$v,'<br>';
}
?>
e)File Functions :
1) stat(file path) : This function Return an array with file information
2)is_file(file path) : Checks wheather the file exist or not & Returns
Boolean value.
3)file_get_contents(file Path) : Returns the file content as a string.
4)file_put_contents(fiel path,data) : Writes the content to the file
overwriting old content and if file does not exists, creates a new file &
adds the content.This function is introduced in 5th version.
109
5)file(file path) : Returns the file content as an array with each line in
the file at a particular index position.
6)filectime(path) : Creates the time of the file.
7)fileatime(file path) : Last access time of the path file.
8)filemtime(file path) : Last modified time of the file.
9)unlink(file path) : Removes the file from the location.
10)filesize(file path) : Returns the size of the file in bites
11)filetype(file Path) : Returns the type of the file (dir or file)
12)fopen(file path,mode) : Opens the file in the specified mode and
returns a file handler for handling the file.
13)fread(file handler, size) : Reads the file content from the current
file handler position upto the specified size.
14)$fp -> file Pointer ..The internal handler which is used for
handling the file.
15)fgetc(file handler) : Reads a single char in the string.
16)fgets(file handler) : Reads a single line from the file..
17)fgetss(file handler) : Reads a single line from the file stripping of
html tags in the file.
18)fwrite(file handler) : This function is used to write the content to
the file
19)ftell(file handler) : Returns the file handler position in the file
20)fseek(file handler) : Moves the file handler to the specified
position in the file
21)fclose(file handler) : Closes the File handler connection.
List of Modes :
r --> Read Mode
r+ --> Read and Write.
110
w --> Write Mode
w+ --> Write & Read.
a --> Append (also writing but without overwriting files)
a+ --> append & read.
x --> Creates a new file & write..
x+ --> Creat a new file for write and read.
rb,rb+,wb,wb+,ab,ab+,xb,xb+ are the modes to be used for binary
files.
Examples for above specified actions :
-----fileput.php
<?php
$file = 'a.txt';
file_put_contents($file,str_repeat("MOd ",5));
?>
-----create.php
<?php
$file = 'c.txt';
$fp = fopen($file,"x");
fwrite($fp," Created");
fclose($fp);
if(is_file($file)){
echo file_get_contents($file);
}
?>
111
-----write.php
<?php
$file = 'b.txt';
$fp = fopen($file,"w");
fwrite($fp,"Modified");
fclose($fp);
if(is_file($file)){
echo file_get_contents($file);
}
?>
-----read.php
<?php
$file = 'test.txt';
$fp = fopen($file,"r");
echo "Pos : ",ftell($fp),'<br>';
echo fread($fp,3),'<br>';
echo "Pos : ",ftell($fp),'<br>';
echo fgetc($fp),'<br>';
echo "Pos : ",ftell($fp),'<br>';
echo fgets($fp),'<br>';
echo fgets($fp),'<br>';
echo 'Pos : ',ftell($fp),'<Br>';
echo fgets($fp),'<br>';
fseek($fp,35);
112
echo fgetss($fp),'<br>';
fclose($fp);
?>
-----func.php
<?php
$file = 'test.txt';
var_dump(is_file($file));
echo '<br>';
echo "size : ",filesize($file),'<br>';
echo "Type : ",filetype($file),'<br>';
echo "Created : ",date("d-m-y h:i:s",filectime($file)),'<br>';
echo "Accessed : ",date("d-m-y h:i:s",fileatime($file)),'<br>';
echo "Modified : ",date("d-m-y h:i:s",filemtime($file)),'<br>';
echo file_get_contents($file),'<br>';
echo "<pre>";
print_r(file($file));
echo '<br>';
print_r(stat($file));
?>
-----append.php
<?php
$file = 'b.txt';
$fp = fopen($file,"a");
fwrite($fp,"Append");
113
fclose($fp);
if(is_file($file)){
echo file_get_contents($file);
}
?>
-----unlink.php
<?php
$file = 'a.txt';
unlink($file);
?>
f)Directory Functions:
1)getcwd() : Current working directory,
2)chdir(path) : Change current working dir to argumented path.
3)is_dir(path) : Checks wheather the argumented dir exist or not and
return Boolean value.
4)mkdir(dirname) : Makes a directory on the current working
location.
5)rename(old name,new name): Changes the name of the directory.
6)rmdir(dir name) : Removes the directory.
7)scandir(path) : Scan the directory and return the directory content
as an array. Returns an array with related path information.
-----getcwd.php
<?php
echo 'Cwd : ',getcwd(),'<br>';
$a = scandir('.',0);
114
foreach($a as $k=>$v){
echo "$k == $v<br>";
}
chdir('..');echo '<hr>';
echo 'Cwd : ',getcwd(),'<br><hr>';
$a = scandir('.',0);
foreach($a as $k=>$v){
echo "$k == $v<br>";
}
?>
-----mkdir.php
<?php
$dir = 'test';
if(!is_dir($dir)){
mkdir($dir);
echo "Directory is created";
} else {
echo "Directory already exists";
}
?>
-----rename.php
<?php
$dir = 'test';
$new = "modified";
115
if(is_dir($dir)){
rename($dir,$new);
echo "Directory name is $new";
}
else {
echo "Directory does not exists";
}
?>
-----rmdir.php
<?php
$new = "modified";
if(is_dir($new)){
rmdir($new);
echo "Directory is removed";
}
else {
echo "Directory does not exists";
}
?>
scandir.php
<?php
echo '<pre>';
var_dump(scandir('.'));
?>
116
Super Globals :
Difference between GET and POST :
GET POST
1.GET data transfers through URL. POST data is send
through request headers
2.GET is insecure POST is secure
3.File cannot be transfered using GET Files can be
transfered
4.Limited data can be send based on length We can send huge
data(8MB) which can be scaled
of URL supported by browser(2KB). up by using
POST_MAX_SIZE
5.It is fast It is not as fast as GET.
6.$_GET is used for accessing $_POST is used for accessing
the GET parameters the POST parameters
GET Ex :
-----get.php
<?php
if(isset($_GET['submit'])){
echo 'Name : ',$_GET['fname'],'<br>';
echo 'Email Address : ',$_GET['email'],'<br>';
$gend = ($_GET['gender'] == 'm')?'Male':'Female';
echo 'Gender : ',$gend,'<br>';
}
117
echo '<hr>';
echo urldecode($_SERVER['QUERY_STRING']);echo '<hr><br>';
?>
-----get.html
<form method='GET' action='get.php'>
Name : <input type='text' name='fname' value=''><br>
E-Mail : <input type='text' name='email' value=''><br>
Gender : <input type='radio' name='gender' value='m'> Male <input
type='radio' name='gender' value='f'> Female<br>
<input type='submit' name='submit' value='Register !'>
</form>
POST Ex :
-----post.php
<?php
if(isset($_POST['submit'])){
echo 'Name : ',$_POST['fname'],'<br>';
echo 'Email Address : ',$_POST['email'],'<br>';
$gend = ($_POST['gender']=='m')?'Male':'Female';
echo 'Gender : ',$gend,'<br>';
$a = $_POST['course'];
echo $a,'<br><hr>';
print_r($a);
}
echo '<hr>';
echo 'The query string : ',$_SERVER['QUERY_STRING'],'<br>';
118
?>
-----post.html
<form method='POST' action='post.php'/>
Name : <input type='text' name='fname' value=''/><br>
E-Mail : <input type='text' name='email' value=''/><br>
Gender : <input type='radio' name='gender' value='m'/> Male <input
type='radio' name='gender' value='f'/> Female <br>
Hobbies : <br>
<input type='checkbox' name='course[]' value='c'/> C-Language <br>
<input type='checkbox' name='course[]' value='p'/> PHP <br>
<input type='checkbox' name='course[]' value='j'/> Java <br>
<input type='submit' name='submit' value='Register'/>
</form>
Server Variables :
-----servervariables.php
<?php
echo 'Get Environment : ',getenv('os'),'<br>';
echo 'Environment Path : ',getenv('path'),'<br>';
echo '<hr>';
echo 'Document Root : ',$_SERVER['DOCUMENT_ROOT'],'<br>';
echo 'Http Host : ',$_SERVER['HTTP_HOST'],'<br>';
echo 'Referer : ',$_SERVER['HTTP_REFERER'],'<br>';
echo 'Method : ',$_SERVER['REQUEST_METHOD'],'<br>';
echo 'User Agent : ',($_SERVER['HTTP_USER_AGENT']),'<br>';
119
echo 'Name of Script : ',$_SERVER['SCRIPT_NAME'],'<br>';
echo 'Query String : ',$_SERVER['QUERY_STRING'],'<br>';
echo 'Remote Ip Address : ',$_SERVER['REMOTE_ADDR'],'<br>';
echo 'PHP Self : ',$_SERVER['PHP_SELF'],'<br>';
echo 'Request URL : ',$_SERVER['REQUEST_URI'],'<br>';
echo 'Script File Name : ',$_SERVER['SCRIPT_FILENAME'],'<br>';
?>
-----phpinfo.php
<?php
echo phpinfo();
?>
 Include_once and required _once : These both will include file
very first time and if already file has been included this will not
include for the second time.
 Defference between include_once & include : Include and
include _once will include the files. But if the path of the file is wrong
include and include_once will generate the wrong message and rest of
the code will be excuted.
Required and required_once : If location of the path is given
wrong this will through a wrong as well as path error and code gets
halted or the execution will be stop.
Ex : a.php
<style>
b{color:green;}
</style>
<b>I am included</b><br><hr>
<?php
120
$a = 10;
if(!function_exists('r')){
function r(){
echo 'I am in a.php and working fine<br>';
}
}
?>
b.php
<?php
include_once("a.php");
include("a.php");
include("a.php");
$b = 20;
echo 'The Value of $a = ',$a,'<br>';
echo 'The Value of $b = ',$b,'<br>';
r();
?>
Headers :
Headers are the information which are exchanged between client and
server for every request and response.
Headers are of two types.
a) Request Headers.
b) Response Headers.
a) Request Headers : These are send from client to server.
121
HTTP Request : GET/php7/info.php HTTP/1.1
Host : localhost
User_Agent : Mozilla/5.0
Accept : text/HTML, application/html
Accept_encoding: gzip,deflate
Connection : keep-alive
keep-alive : 115
Accept_char : ISO-88591-1 utf-8;q=0.7
Ex : apache_request_headers()
b) Response Headers : These are send from server to client.
X-powered-by : php/5.3.1
keep_Alive : timeout=5,max=100
connection : Keep_Alive
Transfer_Encoding : chunted
content_type : text/html
Ex : apache_response_headers()
HTTP Methods :
For every request from the client to server can be made through
various HTTP methods like
GET, POST, PUT, DELETE, HEAD
Headers can be send from php program to the server.
1. headers_list() : Returns an array to the list of the headers which
can be shared from server to client.
122
2. headers_sent() : Returns the boolean value above whether the
headers were send to the client or not.
3.header("<name>:<value>") : Header function should be used in
the page before any output is send to the page.
Header functions are used for redirection and for sending the output
and also for downloading of the files.
Php content in different formats(content type like
html,xhtml,images,pdf,flash,video etc).
Ex :
-----hrds.php
<?php
ob_start();
print_r(apache_request_headers()); echo '<hr>';
var_dump(headers_sent());
header("Name:Rajesh");
header("location:info.php");
print_r(headers_list());
echo '<hr>';
print_r(apache_response_headers());
?>
-----info.php
<?php
echo phpinfo();
?>
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes
PHP HTML CSS  Notes

Contenu connexe

Tendances (20)

HTML and CSS crash course!
HTML and CSS crash course!HTML and CSS crash course!
HTML and CSS crash course!
 
CSS ppt
CSS pptCSS ppt
CSS ppt
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
 
Html forms
Html formsHtml forms
Html forms
 
Form Handling using PHP
Form Handling using PHPForm Handling using PHP
Form Handling using PHP
 
HTML/HTML5
HTML/HTML5HTML/HTML5
HTML/HTML5
 
Javascript
JavascriptJavascript
Javascript
 
HTML
HTMLHTML
HTML
 
HTML Fundamentals
HTML FundamentalsHTML Fundamentals
HTML Fundamentals
 
Html form tag
Html form tagHtml form tag
Html form tag
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
 
Html and css
Html and cssHtml and css
Html and css
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
 
Web development using HTML and CSS
Web development using HTML and CSSWeb development using HTML and CSS
Web development using HTML and CSS
 
HTML
HTMLHTML
HTML
 
Lecture 2 introduction to html
Lecture 2  introduction to htmlLecture 2  introduction to html
Lecture 2 introduction to html
 
HTML5: features with examples
HTML5: features with examplesHTML5: features with examples
HTML5: features with examples
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 

En vedette (13)

Basic Html Notes
Basic Html NotesBasic Html Notes
Basic Html Notes
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
 
php tutorial - By Bally Chohan
php tutorial - By Bally Chohanphp tutorial - By Bally Chohan
php tutorial - By Bally Chohan
 
MTP for MCA
MTP for MCAMTP for MCA
MTP for MCA
 
MTP for MCA
MTP for MCAMTP for MCA
MTP for MCA
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14
 
M.c.a. (sem ii) operating systems
M.c.a. (sem   ii) operating systemsM.c.a. (sem   ii) operating systems
M.c.a. (sem ii) operating systems
 
MTP for MCA
MTP for MCAMTP for MCA
MTP for MCA
 
M.c.a.(sem iii) operation research
M.c.a.(sem   iii) operation researchM.c.a.(sem   iii) operation research
M.c.a.(sem iii) operation research
 
BCA GGSIPU NEW SYALLBUS
BCA GGSIPU NEW SYALLBUSBCA GGSIPU NEW SYALLBUS
BCA GGSIPU NEW SYALLBUS
 
IgnouBCA
IgnouBCAIgnouBCA
IgnouBCA
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 

Similaire à PHP HTML CSS Notes

Workshop 2 Slides.pptx
Workshop 2 Slides.pptxWorkshop 2 Slides.pptx
Workshop 2 Slides.pptxDaniyalSardar
 
Css introduction
Css introductionCss introduction
Css introductionSridhar P
 
Html, css and jquery introduction
Html, css and jquery introductionHtml, css and jquery introduction
Html, css and jquery introductioncncwebworld
 
Css tutorial
Css tutorialCss tutorial
Css tutorialvedaste
 
AttributesL3.pptx
AttributesL3.pptxAttributesL3.pptx
AttributesL3.pptxKrishRaj48
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS PresentationShawn Calvert
 
INTERNSHIP PROJECT PPT RAJ HZL.pdf
INTERNSHIP PROJECT PPT RAJ HZL.pdfINTERNSHIP PROJECT PPT RAJ HZL.pdf
INTERNSHIP PROJECT PPT RAJ HZL.pdfDineshKumar522328
 
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvZahouAmel1
 
Class Intro / HTML Basics
Class Intro / HTML BasicsClass Intro / HTML Basics
Class Intro / HTML BasicsShawn Calvert
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2Erin M. Kidwell
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssTesfaye Yenealem
 
Learn html elements and structure cheatsheet codecademy
Learn html  elements and structure cheatsheet   codecademyLearn html  elements and structure cheatsheet   codecademy
Learn html elements and structure cheatsheet codecademynirmalamanjunath
 

Similaire à PHP HTML CSS Notes (20)

Html
HtmlHtml
Html
 
Workshop 2 Slides.pptx
Workshop 2 Slides.pptxWorkshop 2 Slides.pptx
Workshop 2 Slides.pptx
 
Css introduction
Css introductionCss introduction
Css introduction
 
Html, css and jquery introduction
Html, css and jquery introductionHtml, css and jquery introduction
Html, css and jquery introduction
 
Css introduction
Css  introductionCss  introduction
Css introduction
 
Css tutorial
Css tutorialCss tutorial
Css tutorial
 
AttributesL3.pptx
AttributesL3.pptxAttributesL3.pptx
AttributesL3.pptx
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 
INTERNSHIP PROJECT PPT RAJ HZL.pdf
INTERNSHIP PROJECT PPT RAJ HZL.pdfINTERNSHIP PROJECT PPT RAJ HZL.pdf
INTERNSHIP PROJECT PPT RAJ HZL.pdf
 
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
 
TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0
 
Intodcution to Html
Intodcution to HtmlIntodcution to Html
Intodcution to Html
 
Session ii(html)
Session ii(html)Session ii(html)
Session ii(html)
 
Class Intro / HTML Basics
Class Intro / HTML BasicsClass Intro / HTML Basics
Class Intro / HTML Basics
 
Html Workshop
Html WorkshopHtml Workshop
Html Workshop
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
 
CSS Part I
CSS Part ICSS Part I
CSS Part I
 
Learn html elements and structure cheatsheet codecademy
Learn html  elements and structure cheatsheet   codecademyLearn html  elements and structure cheatsheet   codecademy
Learn html elements and structure cheatsheet codecademy
 

Plus de Tushar Rajput

System analysis and_design
System analysis and_designSystem analysis and_design
System analysis and_designTushar Rajput
 
Unit 6 Privacy and Data Protection 8 hr
Unit 6  Privacy and Data Protection 8 hrUnit 6  Privacy and Data Protection 8 hr
Unit 6 Privacy and Data Protection 8 hrTushar Rajput
 
Unit 5 Intellectual Property Protection in Cyberspace
Unit 5  Intellectual Property Protection in CyberspaceUnit 5  Intellectual Property Protection in Cyberspace
Unit 5 Intellectual Property Protection in CyberspaceTushar Rajput
 
Unit 4 Commerce and Cyberspace
Unit 4 Commerce and CyberspaceUnit 4 Commerce and Cyberspace
Unit 4 Commerce and CyberspaceTushar Rajput
 
Unit 3 Cyber Crimes and Torts 8 hr
Unit 3 Cyber Crimes and Torts 8 hrUnit 3 Cyber Crimes and Torts 8 hr
Unit 3 Cyber Crimes and Torts 8 hrTushar Rajput
 
Unit 2 Regulation of Cyberspace
Unit 2 Regulation of CyberspaceUnit 2 Regulation of Cyberspace
Unit 2 Regulation of CyberspaceTushar Rajput
 
Unit 1 Introducation
Unit 1 IntroducationUnit 1 Introducation
Unit 1 IntroducationTushar Rajput
 

Plus de Tushar Rajput (7)

System analysis and_design
System analysis and_designSystem analysis and_design
System analysis and_design
 
Unit 6 Privacy and Data Protection 8 hr
Unit 6  Privacy and Data Protection 8 hrUnit 6  Privacy and Data Protection 8 hr
Unit 6 Privacy and Data Protection 8 hr
 
Unit 5 Intellectual Property Protection in Cyberspace
Unit 5  Intellectual Property Protection in CyberspaceUnit 5  Intellectual Property Protection in Cyberspace
Unit 5 Intellectual Property Protection in Cyberspace
 
Unit 4 Commerce and Cyberspace
Unit 4 Commerce and CyberspaceUnit 4 Commerce and Cyberspace
Unit 4 Commerce and Cyberspace
 
Unit 3 Cyber Crimes and Torts 8 hr
Unit 3 Cyber Crimes and Torts 8 hrUnit 3 Cyber Crimes and Torts 8 hr
Unit 3 Cyber Crimes and Torts 8 hr
 
Unit 2 Regulation of Cyberspace
Unit 2 Regulation of CyberspaceUnit 2 Regulation of Cyberspace
Unit 2 Regulation of Cyberspace
 
Unit 1 Introducation
Unit 1 IntroducationUnit 1 Introducation
Unit 1 Introducation
 

Dernier

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Dernier (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

PHP HTML CSS Notes

  • 1. 1
  • 2. 2 HTML HTML is a not a scripting language or programming language.It is a simple markup language with the pair of markup tags. The first tag is known as opening tag (or) starting tag. The second tag is known as closing (or) end tag. HTML is used to describe the web pages. HTML can be written in notepad, notepad++, dream viewer, adov and cs5. HTML file can be saved with .html as its extension. The look end of an web page should be same on the all browsers. If it is not same the cross browser compatibility. Tags in html : Heading tags are h1, h2,h3,h4,h5,h6 Ex: - <h1>welcome to html</h1> . . <h6> welcome to html</h6> <hr>: - this tag is used for horizontal line <br>: - this tag is used for break <p>: - this tag is used for paragraph content <b>: - this tag is used for bold content <i>: - this tag is used for italic content <link>: - this tag is used for connect the style sheets <script>: - this tag is used for JavaScript <big>: - this tag is used for big content
  • 3. 3 <strong>: - this tag is used for strong content <blink>: - this tag is used for blink content <del>: - this tag is used for delete the content <strike>: - this tag is used for strike <u>: - this tag is used for underline content <ins>: - this tag is used for insert content <q>: - this tag is used for quotation content <sup>: - this tag is used for super content Ex: - (a+b) <sup> 2</sup> <sub>: - this tag is used for subscript content Entities : Entities are used to describe the symbols (or) special characters on to the web page. We have certain symbols are not available on the keyboard. So such symbols can be inserting through entities. We have mainly two types of entities they are 1. Named Entity 2. Number Entity 1. Named Entity : Syntax: - Ampersand + entity name + semicolon Ex: -&dollar; 2. Number Entity : Syntax: Ampersand + hash + ascci value+ semicolon Ex : &#65; =>A &#153; =>Trademark: tm
  • 4. 4 List Tags : List tags are two types 1. Order list : Grouping of elements in the form of order wise through number, upper alpha (A),lower alpha (a), upper roman, lower roman is known as order list Ex: - Order list.html <ol type='a' start='25'> <li>Nokia</li> <li>Mototola</li> <li>Sony</li> </html> 2. Unorder list : Grouping of elements in the form of disk, square circle are known as unorder list Ex: - <ul type='square'> <li>PHP</li> <li>HTML</li> </ul> Definition list : This is used to maintain the heading the description on to the <dl> tag. Definition term : Definition term creates the heading Definition description : Which holds the description of the content. Dt and dd tags are both child tags of DL. Ex : <dl> <dt>Terms & Conditions</dt>
  • 5. 5 <dd><small><small>some large text matter write here </small></small></dd> </dl> Meta tag : Meta tag is used to generate the traffic on to your web page. Meta tags can be embed into the head tag using Meta tag.  Meta tag helps in search engine ranking on Google page and PTC(pay to click) Ex : Meta.html <html> <head> <title>Meta Tags</title> <meta name='keyword' content='PHP,HTML,JQUERY,CSS,HYDERABAD,Institute,Ameer pet'/> <meta name='description' content='We been in lamp for more than 8years and trained many student ... many have got jobs in PHP ...'/> <meta http-equiv='refresh' content='5;url=http://www.axis- bank.com'/> </head> <body> <h2>We have changed our Website Name from UTI Bank to AXIS Bank ... Sorry for incontinent Please wait for 5 sec it would be Automatically be Redirected</h2> </body> </html>
  • 6. 6 Link tags : Links are used to navigate from one page to another page using inter (or) external links. The attributes we can pass are Target = “-blank” // new web page Target = “-new” // new web page Target = “-self” // open on same page Links can target to mails and also search the link on same page. Ex : linktag.html <html> <head> <title>Link Tags</title> </head> <body> <h3>Links Navigation</h3> <a href='http://www.google.com' target="_blank">Google page</a> || <a href='http://www.facebook.com' target='_self'>Facebook Page</a> || <a href='Tags.html' target="_new"> Tags Content</a> </body> </html> Image tags: Images can be embed into the body tag using image tag. Images have extension of jpg, png, gif etc.,
  • 7. 7 Placing one image on to the web page can be done by two types they are 1.Absolute Path 2.Relative Path 1. Absolute path : Working from the working directory you can call the image from anywhere with respect to its parent directory (or) out of the parent directory (or) external files. Ex : <h2>absolute path</h2> <img src = ‘http://www.google.com/images/mountain.jpg’ alt = ‘beautiful’ border = ‘10’ width = ‘200px’ height = ‘180px;/> 2. Relative path : Using relative path you can work with images on to the same current working directory (or) sub folders did not out of your parent directory. Ex : <h2>relation tags</h2> <img src="suresh.jpg" width='140px' height='150px' border='0' title='suresh'/><br> <img src="../water lilies.jpg" width='200px' height='180px' border='3' title='suresh'/><br> <img src="../../sunset.jpg" width='200px' height='180px' border='3' title='suresh'/><br> <img src="new folder/dsc_0083.jpg" width='200px' height='180px' border='3' title='suresh'/><hr> Tables create : Tables are used to put down content in tabular structure. Table tag can be embed into your body tag using <table>
  • 8. 8 <tr> table row</tr> <td> table data (or) content</td> </table>  The general attributes that we can pass in table tag are Border = “<num>” Width = “<num>” Height = “<num>” Cellpadding = “<num>” Cellspacing = “<num>” Align= left/center/right Background = “image path” Fames = “box/group/lhs/rhs/above/below/vsides/hsides Rules = all/middle/bottom Colspan =“<num>” Rowspan = “<num>” Bgcolor = “color name” Ex : <body> <table border = “1” align = “center” width = “70%”> <tr><td>employee detailsl</td></tr> <table> <tr><td>s.no</td><td>Name</td><td>designation</td></tr> <tr><td>1</td><td>suresh</td><td>php programmer</td></tr> </body> Cell padding : Cell padding is used to maintain the distance between its content and from its wall (or) border Cell spacing : Cell spacing is used to increase the wall (or) the border
  • 9. 9 Frame set : We can divide the body into number of divisions that are passed as an argument based on rows (or) columns working with frame set you should ensure that body tag is not given Note : Frame set is a depreciated tag and would be working with future versions Ex : <frameset cols='30%,25%,*'> <frame src = 'links.html' scrolling='no' > <frame src = 'entities.html' > <frame src = 'list.html' > </frameset> Iframes : Ex : <body> <p align='center'><a href='list.html' target='x'>List Page</a> | <a href='links.html' target='x'>Links Page</a><br><br> <iframe src='list.html' name='x' width='600px' height='200px' ></iframe></p> </body>
  • 10. 10
  • 11. 11 Cascading Style Sheets(CSS) Css stands for cascading style sheet. Css is used to put some styles (or) colors on to the web page. Css can be embed into the html head tag using style tag. There are mainly 3 different flavors to attach this style on to the web page. Which are mainly 1. Internal style sheet 2. External style sheet 3. In-line style sheet 1. Internal style sheet : An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section of an HTML page, by using the <style> tag, like this: <head> <style type="text/css"> hr {color:sienna;} p {margin-left:20px;} body {background-image:url("images/back40.gif");} </style> </head> 2. External style sheet : An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section: <head> <link rel="stylesheet" type="text/css" href="mystyle.css" /> </head>
  • 12. 12 An external style sheet can be written in any text editor. The file should not contain any html tags. Your style sheet should be saved with .css extension. An example of a style sheet file is shown below: hr {color:sienna;} p {margin-left:20px;} body {background-image:url("images/back40.gif");} 3. In-line style sheet : An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly! To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph: <p style="color:sienna;margin-left:20px">This is a paragraph.</p> We have one more style which is given by default by browsers which is not editable External style sheet can be saved with .css as its extension Syntax : (Attributes) element (or) class (or) id {property: value ;} CSS Syntax : A CSS rule has two main parts: a selector, and one or more declarations: The selector is normally the HTML element you want to style. Each declaration consists of a property and a value.
  • 13. 13 The property is the style attribute you want to change. Each property has a value. Selector : Selectors are identifiers which give styles based on elements, class (denoted by period ‘.’), id (denoted by ‘#’).We have 7 kinds of selectors.They are :  Element selector  Class selector  Class with element selector  Id selector  Id with element selector  Attribute selector  Pseudo selector 1.Element selector : Ex : element.html <html> <head> <title>Element Selector</title> <style> h1{color:green;} </style> </head> <body> <h1>Welcome to my Website</h1> </body> </html>
  • 14. 14 2.Class selector : The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements. This allows you to set a particular style for many HTML elements with the same class. The class selector uses the HTML class attribute, and is defined with " . (dot)" In the example below, all HTML elements with class="center" will be center-aligned: 3.Class with Element Selector : Example for Class Selector and Class with Element Selector Ex : class-selector.html <html> <head> <title>Class with Element Selector</title> <style> h1{color:green;} //element selector .x{color:red;} // class selector //.x{font-family:impact;} p.x{font-size:20pt;color:black;} // Class with element selector </style> </head> <body> <h1>Welcome to my Website</h1>
  • 15. 15 <h1 class='x'>This is new Website </h1> <h1>hello This is my next line</h1> <p class='x'>Hello my next page</p> <p>Rajesh</p> </body> </html> 4.Id selector : The id selector is used to specify a style for a single, unique element. The id selector uses the id attribute of the HTML element, and is defined with a "#". The style rule below will be applied to the element with id="para1": 5.Id with Element Selector : Example for Id Selector & Id with Element Selector Ex : Id-selector.html <html> <head> <title>Id with Element Selector</title> <style> h1{color:green;} //element selector .x{color:red;} // class selector //.x{font-family:impact;} p.x{font-size:20pt;color:black;} // Class with element selector #g{background:green;} //id selector p#g{text-transform:uppercase;} //id with element selector
  • 16. 16 </style> </head> <body> <h1>Welcome to my Website</h1> <h1 class='x'>This is new Website </h1> <h1>hello This is my next line</h1> <p class='x'>Hello my next page</p> <p class='x' id='g'>Rajesh</p> <h2 class='x' id='g'>Amith</h2> <h2 class='x' id='g'>David</h3> <p class='x' id='g'>Praveen</p> <p class='x' id='g'>Karthik</p> </body> </html> 6.Attribute selector : Ex : attribute.html <html> <head> <title>Attribute Selector</title> <style> .x{ color:deeppink; font-family:impact; }
  • 17. 17 input[type='text']{ color:deeppink; } </style> </head> <body> Name : <input type='text’ name='name' class='x'><br> username : <input type='text' name='uname'><br> </body> </html> 7.Pseudo selector : Ex : pseudo.html <html> <head> <title>Pseudo Selector</title> <style> p:first-letter{ font-size:30pt; color:deeppink; font-family:arial black; } p:first-line{ color:orange; }
  • 18. 18 </style> </head> <body> <p>This is my first email to all you guys his is my first email to all you guys his is my first email to all you guys his is my first email to all you guys his is my first email to all you guys</p> </body> </html> Css cheat sheet : Font-styles : font-style : italic,normal font-variant : small-caps,narmal,small,caps(capital letters) font-weight : normal,lighter,bold, bolder, number(100->light, 900->bolder) font-size : <num> px; font-family : family of font Text properties : 1. letter-spacing : <num>px 2. word-spacing : <num>px 3. line-height : <num>px 4. text-align : left/center/right/justify ->order from left (or) right 5. text- decoration : name, blink,underline,overline,line-through 6. text-transform : capitalize(upper case/lower case(everything convert)) 7.text-indent : <num>px (distance from line to first letter)
  • 19. 19  The text-align property is used to set the horizontal alignment of a text. Text can be centered, or aligned to the left or right, or justified. When text-align is set to "justify", each line is stretched so that every line has equal width, and the left and right margins are straight (like in magazines and newspapers).  The text-decoration property is used to set or remove decorations from text. The text-decoration property is mostly used to remove underlines from links for design purposes:  The text-transform property is used to specify uppercase and lowercase letters in a text.It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word.  The text-indent property is used to specify the indentation of the first line of a text. Background property : CSS background properties are used to define the background effects of an element. background-color : ‘color name’; background-image : url(image path name); The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element. The background image for a page can be set like this: background-repeat : no-repeat,reapt-x,reapt-y,repeat(*); By default, the background-image property repeats an image both horizontally and vertically. Some images should be repeated only horizontally or vertically, or they will look strange, like this: background-attachment : fixed,scroll;
  • 20. 20 background-position :{x,y}left,center,right,bottom,top When using a background image, use an image that does not disturb the text. Showing the image only once is specified by the background-repeat property: //background : order wise List properties : list-style-type : none,disk,circle,square,decimal,upper-alpha,lower- alpha,upper-roman,lower-roman; list-style-position : outside (*) / inside; list-style-image:url(image path name); Box properties : Padding : inside element Margin auto = center Overflow = visible (*), hidden, auto, scroll Ex : <html> <head> <title>BOX properties</title> <style> //body{margin:0px;} p{text-align:center;} .z{ background:#ccc; padding:15px;
  • 21. 21 width:50%; height:80px; margin:auto; overflow:auto; text-align:justify; } </style> </head> <body> <p> <input type='checkbox' name='t&c' />Terms & Conditions <p class='z'> Some large text matter</p> </p> </body> </html> Border Properties : border-width : <num>px; border-style : solid,groove,inset,outset,double,dotted,dashed; border-color : <color name> //border: order wise Div tag : Div tag stands for division tag.Div tag is the block level element. A block level element creates a block with coming left and right breaks in it.
  • 22. 22 Ex : div tag, p tag, h1 to h6, table tag, ul and li tags In-line element : These particular elements will take the content span only and does not have breaks init Span tag is the natural tag. Ex : <html> <head> <title>in-line element</title> <style> h1 { background : green; display : inline; } b{ Background: gold; } a.{text-align : center; background : yellow; display : block; } </style> </head> <body> <h1>hello</h1><b>hello</b><i>hello</i><p>hello</p> <hr> <span class = ‘a’>hello</span> <div class = ‘a’>hello</div> <hr> <h3> converting block & inline & respectively<h3> <h1> hello</h1>
  • 23. 23 </bold> </html> Display properties : Visibility : we have visible (or) hidden Display : none, in-line, block; Padding : <num>px all sides Padding : top left 0px 0px Bottom right Margin : <num> all sides Margin : top right bottom left 0px 0px 0px 0px Templates : Position properties : Position in css we have absolute, relative and fixed position Relative position : Working from the current position we can move the element anywhere on to the web page but cannot be moved on the top of the position place. Absolute & fixed position : Placing from the current position we can move the element to all corner of the web page and also one top of the position place .once an element declare as fixed (or) absolute this will turn to in-line element and this will also carry ‘7’ index init Ex : position.html <html> <head> <title>Position properties</title>
  • 24. 24 <style> div{background:blue;color:#fff;font-size:17pt; font- weight:bold;padding:10px;margin:4px;} .r{background:gold;color:#000;position:relative;left:30px;top:120px;} .a{background:blue;position:absolute;top:50px;left:6px;} .f{background:deeppink;color:#000;position:fixed;bottom:0px;right:0 px;} </style> </head> <body> <div>Normal Position</div> <div class='a'>Absolute Position</div> <div class='r'>Relative Position</div> <div class='f'>Fixed Position</div> <h1>some large text matter </h1> <h1> some large text matter </h1> <h1> some large text matter </h1> <h1> some large text matter </h1> </body> </html>
  • 25. 25
  • 26. 26 JavaScript  JavaScript is client side scripting language.  JavaScript is the case sensitive.  JavaScript can be used for AJAX integration and validation.  JavaScript can be embed into the head tag and body tag using script tag.  JavaScript can be saved with .js as its extension. Content:  Variables  Datatypes  Operators (Assignment, Arthamatic, Post/Pre [Inc/Dec], Comparission, Relational, Conditional, Logical,Ternary)  Alert,prompt,confirm  Built in Functions (Arrays,Date,Math,String)  DOM (Document Object Module)  Navigator,images,screen,location,history  Document – (getElementById, getElementsByTagName, getElementsByName)  Events :  General Events (onclick(), ondblclick(), onload(), onunload(), onreset(), onsubmit(), onfocus(), onblur(), onchange())  Mouse Events (onmouseover(), onmousemove(), onmousedown(), onmouseout() )  Key Board Events – (onkeyup() , onkeydown() ) Document.write () : document.write is the printing method in javascript.Which is output statement to the browser. Ex: first.html <html> <head>
  • 27. 27 <script src='ext.js' type='text/javascript' language='javascript'></script> <script> document.write('This is Called from Head Tag<br>'); </script> </head> <body> <h1>Welcome</h1> <script> document.write('This is Called from Body Tag<br>'); </script> </body> </html> ext.js:- document.write('<h1>This is called from External Page</h1>'); Variables : Variables are case sensitive. Declaring a variable in JavaScript as variable name = value; Variables are "containers" for storing information. Ex : var a = 10; var = default The correct method to declare are : Var a = 10; Var_a = 10; Var first-name = ‘suresh’;
  • 28. 28 Var firstName = ‘suresh’; Var $name = ‘suresh’; Wrong method : Var #name = ‘suresh’; Var 1a = 10; Var first name = ‘suresh’; Data Types : String : Collection of characters inside a single (or) double quotations are known as string ,working with single quotation and adding double quotation in it is valid.But adding single quotation inside a single quotation is not valid. Ex : datatypes.html <html> <head> <script> var a = 10; document.write('<h1>'+a); document.write(' - '); document.write(typeof(a)); document.write('<br>'); var f = 10.25; document.write(f); document.write(' - '); document.write(typeof(f));
  • 29. 29 document.write('<br>'); firstname = 'Rajesh'; document.write(firstname+' - '+typeof(firstname)+'<br>'); firstname = firstname+' Kumar'; document.write(firstname+' - '+typeof(firstname)+'<br>'); firstname += 'B'; document.write(firstname+' - '+typeof(firstname)+'<br>'); document.write('<hr>String Methods<hr>'); document.write('i'll Pay the Bill Tomorrow'); </script> </head> <body> <h1>Welcome</h1> </body> </html> Operators : 1.Assignment operator: ‘ = ‘ is used to assign values. The assignment operator ‘=’ is used to assign values to JavaScript variables. Ex : <script> document.write('<h1 align="center">Assignment Operator</h1>'); var x = 10;
  • 30. 30 document.write("The Value is : "+x); </script> 2.Arithmetic operator: - The arithmetic operator ‘ +’ is used to add values together. Arithmetic operators are used to perform arithmetic between variables and/or values. Ex : <script> document.write('<h1 align="center">Arthamatic Operator</h1>'); a = 5; b = 3; document.write("Addition : "+(a+b)+'<br>'); document.write("Multiplication : "+(a*b)+'<br>'); document.write("Division : "+(a/b)+'<br>'); document.write("Minus : "+(a-b)+'<br>'); document.write("Modulus : "+(a%b)+'<br>'); </script> 3.Comparision operator : Comparision operators are used in logical statements to determine equality or difference between variables or values. Ex : <script> Document.write('<h1 align="center">comparision Operator</h1>'); if(10 != '10'){
  • 31. 31 document.write('<h2>Correct</h2>'); } else { document.write('<h2>Not Correct</h2>'); } document.write('<h1 align="center">Post & Pre Increment</h1>'); m = 10; n = (m++)+(++m)+(m++)+(++m); document.write('The Value of m is : '+m+'<br>The Value of n is : '+n+'<br>'); </script> 4.Relational operator : < , > , <= , >= 5.Logical operator : &&(and) -- ||(or) 6.Ternary operator : Syntax for Ternary Operator : Var a= 10; Type = (a%2 == 0)? ‘even number’: ‘odd number’; //document.write(“the value you entered is : ”+type); document.write(type); Conditions : 1.If else : Whenever a condition is ‘if’ it is true that part of the constructor will be excuted.if condition is fail ‘else’ part would get executed.
  • 32. 32  Conditional statements are used to perform different actions based on different conditions  use this statement to execute some code if the condition is true and another code if the condition is false Syntax : If (cond) { //code } else { // code }; 2.If else if : if else if (or) ladder condition will take more than one condition (or) multiple conditions. If all the conditions fail in if else if constructor then only else part get executed  Use this statement to select one of many blocks of code to be executed Syntax : If(cond) { //code }
  • 33. 33 else if (cond) { //code } else if (cond) { //code } . . else { //default value; } 3.Switch : Use the case in-order wise. This is main concept in switch case  Use this statement to select one of many blocks of code to be executed  Conditional statements are used to perform different actions based on different conditions. Syntax : switch(n) { case 1: execute code block 1
  • 34. 34 break; case 2: execute code block 2 break; default: code to be executed if n is different from case 1 and 2 } Looping methods : While: do-while: Syntax: Syntax: Initialize method Initialize While (cond) do { { //code //code } } 1.While : Working with while loops it will first check the initialize part and checks the condition. If condition is true it will get into the constructor and takes place until condition fail and comes out of the constructor.  loops through a block of code while a specified condition is true
  • 35. 35 2.Do-while : This will also checks the initialized part .but for only first time it will get into the constructor and execute the code and checks the conditions later and if condition is true looping takes place (or) else it come out of the constructor with at least single time execution code 3.For-loop : For loop first initialize condition an inc/dec will be done on same (single) line for the every first time it will initialize with part them check within condition if condition is true the constructor will get excuted.condition fail will come out of the for loop (constructor)  Loops execute a block of code a specified number of times, or while a specified condition is true. Syntax : For (initialize; condition; inc/dec ) { //code } Arrays : A variable which can hold more than one value is none as array (or) super variable as array can be defined is JavaScript as Var a = new Array (values); // a->super variable  To find the length of the array we can go with length = array name.length;  If the array index is been initialize more than the current index++ then memory is wasted in JavaScript  In arrays initializing string index the printing method will not work in JavaScript Note : - document.write() (or) looping method will not able to print string indexes
  • 36. 36  While, do-while , for-loop will not print string indexes in JavaScript so to print string indexes we can go with Syntax: - for (var name in Array name)  For is key word in JavaScript which will print the string index  The Array object is used to store multiple values in a single variable.  An array is a special variable, which can hold more than one value, at a time. Create an Array : An array can be defined in three ways. The following code creates an Array object called myCars: 1: var myCars=new Array(); // regular array (add an optional integer myCars[0]="Saab"; // argument to control array's size) myCars[1]="Volvo"; myCars[2]="BMW"; 2: var myCars=new Array("Saab","Volvo","BMW"); // condensed array 3: var myCars=["Saab","Volvo","BMW"]; // literal array Ex : Array.html <script> var a = new Array(10,20,30,40); document.write('The Array is : '+a+'<br>'); document.write('Length of Array : '+a.length+'<br>'); document.write('Index at 2 : '+a[2]+'<br>'); a[2] = a[2]*2; document.write('The Array is : '+a+'<br>'); a[4] = 'New Value';
  • 37. 37 document.write('The Array is : '+a+'<br>'); var b = new Array(); b[0] = 100; b[1] = 200; b[2] = 300; b[3] = 400; b['Name'] = 'Rajesh'; b['Age'] = 30; b[7] = 700; b[10] = 1000; document.write('<hr>Single string Index : '+b['Name']+'<hr>'); document.write('The Array is : '+b+'<br>'); for(i=0;i<b.length;i++){ document.write('Index at : '+i+' = '+b[i]+'<br>'); } document.write('<hr>'); for(c in b){ document.write(c+' = '+b[c]+'<br>'); } document.write('<hr>'); var d = [10,20,30]; document.write('The Array in d is : '+d+'<br>'); document.write('The Array in d is : '+d.length+'<br>'); document.write('<hr>');
  • 38. 38 var e = {'Name':'Rajesh','Age':30,10:20,'Status':'Active'}; document.write('The Array in d is : '+e+'<br>'); for(i=0;i<e.length;i++){ document.write('Index at : '+i+' = '+e[i]+'<br>'); } for(c in e){ document.write(c+' = '+e[c]+'<br>'); } </script> Double dimensional array: An array can have more than one array is called double dimensional array. Ex : douledimensionarray.html <html> <head> <script> var a = [[1,'Ajay',[45,62,49,72,55,84]],[2,'Rajesh',[48,62,94,72,38,62]],[3,'Sur esh',[48,63,82,97,45,28]]]; //document.write(a[1][1]); document.write('Name is : '+a[2][1]); document.write("<table border='1' align='center' width='60%' >"); document.write("<tr><th colspan='9'>Student Marks Memo Report </th> ");
  • 39. 39 document.write("<tr><td rowspan='2'>Roll No</td> <td rowspan='2'>Name</td><td colspan='6' align='center'>Subjects</td><td rowspan='2'>Pass/Fail</td></tr>"); document.write("<tr><td>English</td><td>Hindi</td><td>Telugu </td> <td>Maths</td><td>Science</td><td>Social</td></tr>"); document.write("<tr><td>"+a[0][0]+"</td></tr>"); </script> </head> <body> <tr><td><script>document.write(a[1][0]);</script></td><td><script> document.write(a[1][1]);</script></td></tr> </table> </body> </html> Array built-in Functions : Join : Join is the pre-defined key-word in the JavaScript .which will convert the given array into the separator passed default separator is coma (,). Concat : concat is joining more than array in single array is called concat. Reverse : reverse in JavaScript the array last being is first. First is last without (descending order) the original array will also get affected. If we use reverse function. Sort : sort is nothing but given the order is ascending order . Unshift : unshift will add the value at the starting of the array. The variable use for unshift will holds the length of the array and the original array would get affected.
  • 40. 40 Shift : shift function will not hold any arguments should will remove the starting value of the array.The variable unshift will hold the removed value. Push : push is nothing but insert the value into the array at the end of array is called push. Pop : pop is nothing but remove the last value in the array is called the pop. Ex : arraybuiltin.html <script> var a = new Array('This','is','my','new','car'); document.write('The Original Array is : '+a+'<br>'); b = a.join(' '); document.write('Join Method : '+b+'<br>'); var a = new Array(10,20,30); var b = new Array(40,50); var c = new Array(60,70,80); document.write("Concat Two Arrays : "+a.concat(b)+"<br>"); document.write("Concat All Given Array : "+a.concat(b.concat(c))+" <br>"); var a = new Array('Ajay','Raju','Amith','Zebra','Arjun'); b = a.reverse(); document.write("Reverse of an Array : "+b+'<br>'); document.write("Original Array : "+a+'<br>'); var a = new Array('Ajay','Raju','Amith','Zebra','Arjun'); b = a.sort(); document.write("Assending Order : "+b+'<br>');
  • 41. 41 document.write("Original Array : "+a+'<br>'); b = a.reverse(); document.write("Reverse With Desending Order : "+b+'<br>'); document.write("Original Array : "+a+'<br>'); var x = new Array(10,20,30); b = x.unshift(5); document.write("Unshift Method : "+x+'<br>'); document.write("The Value Stored in B : "+b+'<br>'); var x = new Array(5,10,20,30); b = x.shift(); document.write("shift Method : "+x+'<br>'); document.write("Removed Value is stored B : "+b+'<br>'); var x = new Array(5,10,20,30); b = x.push(40); document.write("Push last Value to Array Method : "+x+'<br>'); document.write("B holds the length of the Array: "+b+'<br>'); var x = new Array(5,10,20,30); b = x.pop(); document.write("Pop Removes last Value in Array : "+x+'<br>'); document.write("B holds the Removed Value: "+b+'<br>'); </script> Functions:- Functions in javascript are case sensitive once declare a function name and try to re-declare. The same function name will overwrite previous function name. Functions are used to debug the code and
  • 42. 42 analize the errors easily. Working with length of the code will be reduced. We have mainly 4 types of the functions in JavaScript that is 1. Function without arguments and return value 2. Function with arguments and no return value 3. Function with return value and no arguments 4. Function with arguments and return value Syntax : Function function name (arguments, arg) { //code } 1. Function without arguments and return value Ex : <script> test(); function test(){ document.write('This is Function without Aurgument<br>'); document.write('This is my function Content<br>'); } function test1(){ document.write('Overwritten is done on the previous printing methods<br>'); } test();
  • 43. 43 test(); </script> <body> <script> test(); </script> </body> 2. Function with arguments and no return value Ex : <style> .error{background:gold;color:green;padding:10px;margin:auto;width: 60%;font-size:18pt;} .success{background:black;color:#fff;padding:10px;margin:auto;widt h:60%;font-size:18pt;} </style> <script> function welcome(name){ document.write("Welcome ! "+name+'<br>'); } welcome('Rajesh'); welcome('Amith'); function statement(type,message){ document.write("<div class='"+type+"'>"+message+"</div>"); } //statement("error","Welcome Guest ! ");
  • 44. 44 statement("success","Welcome Rajesh"); </script> 3. Function with return value and no arguments Ex : <script> function test(){ document.write('This is line 01<br>'); document.write('This is line 01<br>'); return 10 2; document.write('This is line 01<br>'); document.write('This is line 01<br>'); } test(); var x = test(); document.write('The Value in x is : '+x+'<br>'); </script> 4. Function with arguments and return value Ex : <script> function square(num){ return num*num; } document.write('The Square root of 5 is : '+square(5)+'<br>'); document.write('The Square root of 5 is : '+square(square(5))+'<br>');
  • 45. 45 </script> Math built-in function : In JavaScript we have mainly seven kinds of math objects which are pre-defined and can be called respective key-words. Which are included in JavaScript library. Ex : math.html <script> function r(txt){ document.write('<h2>'+txt+'</h2>') } r("<u>Javascript Predefined Math Constant Object </u>"); r('Eulers Constant : '+Math.E); r('Pi Value : '+Math.PI); r('SQRT OF 2 : '+Math.SQRT2); r('Natural Log 2: '+Math.LN2); r('Natural Log 10 : '+Math.LN10); r('Log base 2 of Eulers : '+Math.LOG2E); r('Log base 10 of Eulers : '+Math.LOG10E); r("<u>Javascript User - defined Math Object </u>"); r('Max Value : '+Math.max(10,20,30)); r('Min Value : '+Math.min(10,20,30)); r('Sqrt Value : '+Math.sqrt(25)); r('2 pow 4 : '+Math.pow(2,4)); r('Absolute Value : '+Math.abs(-9));
  • 46. 46 r('Ceil Value : '+Math.ceil(2.11111)); r('floor Value : '+Math.floor(2.9999)); r('round Value : '+Math.round(2.5111111)); r('Random Number : '+Math.random()); r('Number Between 1 to 1000 : '+Math.round(Math.random()*1000)); </script> String built-in functions : Ex : stringbuilt.html <script> function r(txt){ document.write(txt+'<br>'); } var str = "lamp Institute"; r('String Value = '+str); r("Length of the String = "+str.length); r("Color of String = "+str.fontcolor('green')); r('Upper Case = '+str.toUpperCase()); r('Lower Case = '+str.toLowerCase()); r('Big Font = '+str.big()); r('Bold Font = '+str.bold()); r('Small Font = '+str.small()); r('Italic Font = '+str.italics()); r('Superscript = '+str.sup()); r('sub script = '+str.sub());
  • 47. 47 r('<hr><h2><u>Slice Function([begin, stop]) </u></h2>'); r('Slice(4) = '+str.slice(4)); r('Slice(4,8) = '+str.slice(4,8)); r('Slice(-9) = '+str.slice(-9)); r('Slice(-9,8) = '+str.slice(-9,8)); r('Slice(-9,-3) = '+str.slice(-9,-3)); r('<hr><h2><u>Substring Function([From, to]) </u></h2>'); r('substring(4) = '+str.substring(4)); r('substring(4,8) = '+str.substring(4,8)); r('substring(4,2) = '+str.substring(4,2)); //r('substring(-9) = '+str.substring(-9)); r('<hr><h2><u>substr([start, length]) </u></h2>'); r('substr(4) = '+str.substr(4)); r('substr(5,8) = '+str.substr(5,8)); r('substr(-9) = '+str.substr(-9)); r('substr(-9,2) = '+str.substr(-9,1)); r('CharAt(0) = '+str.charAt(1)); r('charCodeAt(1) = '+str.charCodeAt(1)); //ascill Value of Index mob = 'Z123456789'; r('charCodeAt = '+mob.charCodeAt(0)); r('Indexof = '+str.indexOf('T'));//-1 r('lastIndexof = '+str.lastIndexOf('t')); r('indexOf = '+str.indexOf('t',9)); r('Search = '+str.search('z'));//-1
  • 48. 48 r('Match = '+str.match('z'));//null </script> Mobile function : Ex : mob.html <script> function r(txt){ document.write(txt+'<br>'); } mob = "8855644045"; r(isValidMobile(mob)); function isValidMobile(val){ if(val.length != 10){ return "Please Enter 10-Digit Mobile Number"; } f = val.charAt(0); if(f == '7' || f == '8' || f == '9'){ } else { return 'Please Check the First Digit of Number & try Again'; } return isNumeric(val); } function isNumeric(val){ for(i=0;i<val.length;i++){
  • 49. 49 ascii = val.charCodeAt(i); if(ascii < 48 || ascii >57){ return 'Only Numbers Allowed Please Check again'; } } return 'Valid Mobile Number'; } </script> Date functions: - Date function can be defined with variable is equal to new date. This function is pre-defined in JavaScript which will explain the system timing (or) running the domain it will capture the running domain. Get time () : This is unique time constant which is created find generate number of milliseconds right from night jan 1st 1970. Ex : date.html <script> function r(txt){ document.write(txt+'<br>'); } var d = new Date(); r('The value in d is : '+d); r('Unix Time Constant that is Midnight Jan 01,1970 (no of millseconds : ) '+d.getTime()); r('Date : '+d.getDate()); r('Day : '+d.getDay());
  • 50. 50 r('Month : '+(d.getMonth()+1));// 0 -11 r('Year : '+d.getYear());//works only in ie... r('FullYear : '+d.getFullYear()); r('Hours : '+d.getHours()); r('Minutes : '+d.getMinutes()); r('Seconds : '+d.getSeconds()); r('Time is : '+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds()); </script> DOM : DOM contains these layers 1.IMAGES 2.LOCATIONS 3.SCREEN------------------> Get Element ById 4.DOCUMENTS-----------> GetElementByTagName 5.NAVIGATOR------------ > GetElementByName 6.EMBED Ex : dom.html <script> function dochange(){ document.testForm.fname.value = alert("Please Enter"); document.testForm.fname.value = 'Enter Name'; document.testForm.lname.style.border="2px solid red"; document.testForm.lname.style.width="200px"; }
  • 51. 51 </script> <body> <form name='testForm'> First Name : <input type='text' name='fname' /><br> Last Name : <input type='text' name='lname'/><br> <input type='button' name='change' value='DoChange' onclick="javascript:dochange();"/> </form> </body> Get Element ById : This particular function will match the id of the element and that particular matching function will get executed Ex : getElementById.html <script> function dochange(){ var x = document.getElementById('test').value; document.getElementById('test').value = x.toUpperCase(); document.getElementById('test').style.color = 'red'; } </script> <body> <form name='testForm'> First Name : <input type='text' name='fname' id='test' onblur="dochange();"/><br> First Name : <input type='text' name='lname' id='fldtest' onkeyup="dochange();"/>
  • 52. 52 </form> </body> GetElementByTagName : This particular function will match tag name and excute the function which we are passing as a tag name Ex : getElementsByTagName.html <script> function dochange(){ var a = document.getElementsByTagName('div'); for(i=0;i<a.length;i++){ a[i].style.width = '400px'; a[i].style.background = '#ddd'; a[i].style.border = '4px dotted green'; } } </script> <body onmouseover='dochange();'> <h1>Welcome to My Web Page</h1> <p>This is my First Page</p> <p>This is my First Page</p> <p>This is my First Page</p> <p>This is my First Page</p> <div>What is Social Hub</div> </body>
  • 53. 53 GetElementByName : This particular function will match element name and that part of the function will get excutes. Ex : getElementsByName.html <script> function dochange(){ var a = document.getElementsByName('x'); for(i=0;i<a.length;i++){ a[i].style.width = '400px'; a[i].style.background = '#ddd'; a[i].style.border = '4px dotted green'; } } </script> <body onmouseover='dochange();'> <h1>Welcome to My Web Page</h1> <p>This is my First Page</p> <p>This is my First Page</p> <p>This is my First Page</p> <p>This is my First Page</p> <div>What is Social Hub</div> </body> Note 1 : As ids are unique we have singular matching so we can getElementById as singular.
  • 54. 54 Note 2 : GetElementByTagName & ByName works the array format and these are plural. Events : Whenever an event is trigger and then that particular matching function will excuted. a)innerHTML : innerHTML is used to push the dynamic values on to the HTML page. b)set Interval : setInterval is pre-defined key-word in JavaScript which takes 2 arguments the first argument can be expression (or) function the second argument can be number of milliseconds. c)Alert : Alert gives you a single button option until it is click It will allowed you to navigate on the server. Ex : alert.html <script> alert("Please Agree with Our Terms & condition"); </script> <body> Welcome </body> d)Confirm : Confirm is used two options until something is being click. It won’t allowed to navigate the server and if it is click based on the values it will moved to the respect pages. Ex : confirm.html <script> var x = confirm("Are You legally 18+ then enter to site"); if(x == true){ document.write("Welcome to my Terrorist Site");
  • 55. 55 } else { document.write("Thank You for leaving Please <a href='http://www.google.com'>Click Here</a>"); } </script> <body> </body> e)Eval : Eval is pre-defined function in JavaScript which will evaluate the given function in between the JavaScript (function) f)parseINT : This is pre-defined function in JavaScript which will convert the floating value into integer value. g)parseFLOOT : This is pre-defined function in JavaScript which will convert the integer value into floating value. Ex : innerHTML & set Interval time.html <script> function r(txt){ document.write(txt+'<br>'); } function currTime(){ var d = new Date(); var time = timeFormat(d.getHours())+':'+timeFormat(d.getMinutes())+':'+timeFo rmat(d.getSeconds()); return 'Present Time : '+time; } function timeFormat(val){ return ((val<10)?'0':'')+val;
  • 56. 56 } function writeTime(id){ return document.getElementById(id).innerHTML = currTime(); } </script> <body> <div id='currentTime' align='right'> <script> r(currTime()); setInterval("writeTime('currentTime')",1000); </script> </div> </body>
  • 57. 57
  • 58. 58 PHP  Rasmus Lerdorf is the founder of the PHP in 1995.  PHP is the server side scripting language.  Php needs a server to excute the file.  Php files should be saved with .php as its extension ".php3", or ".phtml"  Or else our server will not excute unknown extension apart from .html, .cpi, .cgs,  Php supports all the data bases that are present in the market Ex:-mySql,mssql,infonix,Sybase,ibmdb2,postgresql………etc  Php can be worked on all the operating systems that is windows,linux,max,solaries…etc  Php can communicate with different servers Ex:-SMTP(Simple mail transfer protocal), imap (internet max access protocal), LDAP, Informix, Oracle, Sybase, Solid, PostgreSQL  PHP can be install as a software tags we get many of the server files Ex : Xampp, Wamp, easy php, mamp  PHP stands for PHP: Hypertext Preprocessor  PHP is an open source software  PHP is free to download and use  PHP is easy to learn and runs efficiently on the server side Xampp : Xampp stands for x------------------------>platform(windows,linux,mac,solaries) a------------------------->apache(web server) m------------------------>mysql(database file) p------------------------->perl(perl scripting in php) p------------------------->php/my admin (web database tool) php current version is 5.3.8
  • 59. 59 Wamp : Wamp stands for w------------------------>window exv a------------------------>apache(web server) m------------------------>mysql(database file) p------------------------>php/my admin (web database tool) Mamp : Mamp stands for m------------------------>mac ‘os’ a------------------------->apache(web server) m------------------------>mysql(database file) p------------------------->php/my admin (web database tool) Apache contain the 1-65535 ports.In that 1-1024 are pre-reserved ports. Tmp : Tmp holds session details & temp upload files. Htdocs : After installing xampp we have to store our files into the folder called htdocs. Once files are saved in htdocs we can open with the location path as http://localhost/abc(foldername)/first.php Echo : echo is the output method in php. Basic PHP Syntax : <?php echo “universal way of writing php<br>”; ?> <script language = ‘php’>
  • 60. 60 echo “javascript way of writtting php<br>”; </script> <? echo”short tag way of writing php<br>”; ?> <% 1echo “asp way of writing php<br>”; %> Comments in PHP : In PHP, we use // to make a one-line comment or /* and */ to make a comment block <html> <body> <?php //This is a comment /* This is a comment block */ ?> </body> </html>
  • 61. 61 Printing methods in php : a.Echo : echo is an argument can print multiple arguments. Echo as a function can print only one argument. b.Print : print is an argument can print only one argument.print also a function Ex: - print”arg<br>”; c.Printf : printf will take formatting string with respected values as print Ex : printf(“(int%d) (float%f) (string %s) (asci%c)”); d.Print-r : print-r will print array of string Ex: - $g = array (10,20,30,true,’kalam’); Print-r($g); e.Var-dump : It is also printing method which is used debugging the errors very easily. This not used in production level (live environmental ) Ex : var-dump($g); <h1>Printing Methods in PHP</h1> <?php $a = 10; $b = 20; $c = 30; echo "Arg01","Arg02","Arg03<br>"; echo $a,$b,$c,'<br>'; echo ("Arg01<hr>"); print "Arg01<br>"; print("Arg01<hr>");
  • 62. 62 printf("(int %d) (float%.2f) (string %s) (Ascii %c) ",22.25,10.2545,'Rajesh',97); echo '<hr>'; $g = array(10,20,30,true,'Rajesh'); print_r($g); echo '<hr>'; var_dump($g); ?> Controlling : Ex : controlling.php <style> b{color:green;} </style> <?php echo "line 01<br>"; echo "line 02<br>"; echo "line 03<br>"; ?> <b>This is Bold Tag</b><hr> <?php if(false){ echo "<b>The 1<sup>st</sup> is Executed<br></b>"; } else { echo "<b>The 2<sup>nd</sup> is Executed<br></b>";
  • 63. 63 } ?> <hr> <h2>Alternate Method</h2> <?php if(true){ ?> <b>The 1<sup>st</sup> is Executed<br></b> <?php } else { ?> <b> The 2<sup>nd</sup> is Executed<br></b> <?php } ?> Variables :  Variables are "containers" for storing information.  Variables in PHP starts with a $ sign, followed by the name of the variable.  The variable name must begin with a letter or the underscore character.  A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _).  A variable name should not contain spaces.
  • 64. 64  Variable names are case sensitive (y and Y are two different variables). Ex : variables.php <h1>Variables in php</h1> <?php $a = 10; $name = 'Rajesh'; $_name $_name $n123 $_1232 $1_name $first_Name echo 'The Value is : ',$a.'<br>'; echo 'The Name is : ',$name,'<br>'; ?> <script> var a = 15; document.write('The Value of a is : '+a+'<br>'); </script>  In PHP, a variable does not need to be declared before adding a value to it.
  • 65. 65  In the example above, notice that we did not have to tell PHP which data type the variable is.  PHP automatically converts the variable to the correct data type, depending on its value.  In a strongly typed programming language, you have to declare (define) the type and name of the variable before using it. PHP has four different variable  local  global  static  Super global array variable Local variable : A variable declared within a PHP function is local and can only be accessed within that function. Ex : localvariable.php <?php function test(){ $a = 10; echo 'The Value of $a inside function is : ',$a,'<br>'; } test(); echo 'The Value of $a Outside Function is : ',$a,'<br>'; ?> Static variable : When a function is completed, all of its variables are normally deleted. However, sometimes you want a local variable not to be deleted. To do this, use the static keyword when you first declare the variable.
  • 66. 66 Ex : staticvariable.php <?php function test(){ $a = 10; static $b = 20; echo 'The Value of $a inside function is : ',$a,'<br>'; echo 'The Value of $a inside function is : ',$b,'<br>'; $a++; $b++; } echo 'The Value of $b outside is : ',$z,'<br>'; test(); test(); ?> Global variable : Global scope refers to any variable that is defined outside of any function. Global variables can be accessed from any part of the script that is not inside a function. To access a global variable from within a function, use the global keyword: Ex : global.php <?php $x = 10;
  • 67. 67 echo 'The Value of $x = ',$x,'<br>'; function test(){ //global $x; echo 'The Value of $x inside Function = ',$x,'<br>'; echo '$GLOBALS["x"] = ',$GLOBALS['x'],'<br>'; } test(); ?> Super global array variable : ‘$ global’ is the super global array variable. This is the pre-defined keyword. In php we have mainly some of the super global variables. This can be used with their keywords. i) $_EVN : This is used for getting the information of your operating system ($_ENV (PATH)) ii) $_SERVER : This will give you the information about your server(apache information) iii) $_GET : It is used for form processing through get method (or) query string iv) $_POST : This is used for form processing through post method in secure manner v) $_REQUEST : It will send the form through both get and post and cookie vi)$_COOKIE : This is used to get the information about the browser who is using the web(computer) vii)$_SESSION : It is used to get the information of the user in between login and logout details are store at server machine.
  • 68. 68 Operators : 1. Assignment operator: = is used to assign values to variables in PHP 2. Arithmetic operator: +,-,/,*,% 3. Increment & decrement operator: i++,++I & i--, --i 4. Comparison operator: ==,!= ,=== 5. Relational operator: <=, >=, <> 6. Logical operator: &&, ||, and, or 7. Error handling operator : 8. Scope resolution & this operator : ::----->scope, &------->this Ex : operator.php <?php echo '<h1 align="center">Assignment Operator</h1>'; $a = 10; echo 'The Value is : '.$a.'<br>'; echo 'The Value is Added by 2 : ',$a += 2,'<br>'; $name = 'Rajesh'; echo 'My name is : '.$name,'<br>'; $name .= ' Kumar'; $name = $name.' Kumar';
  • 69. 69 echo 'My name is : ',$name,'<br>'; echo '<h1 align="center">Arthamatic Operator</h1>'; echo 'The value of 2+3 : ',2+3,'<br>'; echo 'The Value of 2-3 : ',2-3,'<br>'; echo 'The Value of 2/3 : ',2/3,'<br>'; echo 'The Value of 2*3 : ',2*3,'<br>'; echo 'The Value of 2%3 : ',2%3,'<br>'; echo '<h1 align="center">Increment & Decrement [INC/DEC]</h1>'; echo '<h2>POST & PRE increment</h2>'; $x = 10; echo 'The Value of $x = ',$x,'<br>'; echo 'The Value of $x++ = ',$x++,'<br>'; echo 'The Value of $x = ',$x,'<br>'; echo 'The Value of ++$x = ',++$x,'<br>'; echo 'The Value of $x = ',$x,'<br>'; echo '<h2>POST & PRE Decrement</h2>'; echo 'The Value of $x-- = ',$x--,'<br>'; echo 'The Value of $x = ',$x,'<br>'; echo 'The Value of --$x = ',--$x,'<br>'; echo 'The Value of $x = ',$x,'<br>'; echo '<h1 align="center">Comparision Operator</h1>';
  • 70. 70 var_dump(10 == 10);echo'<br>'; var_dump(10 != '10');echo'<br>'; echo '<h1 align="center">Relational Operator</h1>'; var_dump(10<=10);echo '<br>'; var_dump(10<>'10');echo '<br>';//not Equal to echo '<h1 align="center">logical Operator</h1>'; var_dump(true && true);echo '<br>'; var_dump(true && false);echo '<br>'; var_dump(true || true);echo '<br>'; var_dump(true || false);echo '<br>'; var_dump(false AND FALSE);echo '<br>'; var_dump(false OR FALSE);echo '<br>'; echo '<h1 align="center">Error Handling Operator</h1>'; echo @sqrt(); //@test(); echo 'Some Data'; echo '<h1 align="center">Scope Resolution & this Operator {:: & - >(this)}</h1>'; class A{ static $z = 100; public $a = 20; public $k = 50;
  • 71. 71 protected $b = 30; private $c = 40; function test(){ echo "A Test Function called inside Class A"; } } $obj = new A; echo $obj->a,'<br>'; echo $obj->k,'<br>'; //echo $obj->b,'<br>'; //echo $obj->c,'<br>'; echo ' The Static Value is : ',A::$z,'<br>'; echo 'The Function inside Class is : ',$obj->test(),'<br>'; ?> Type Casting: - Conversion of the one data type into another data type is known as type casting. in php we have mainly two types of costing 1. Temporary type casting 2. Permanent type casting 1. Temporary type casting : Casting which can be done for single step by pre-defined the data type keyword. That particular variable will hold Temporary type casting.
  • 72. 72 Ex : temporary.php <?php $x = "10.254Kgs"; var_dump($x);echo "<br>"; var_dump((int)$x); echo "<br>"; var_dump($x); echo '<br>'; var_dump((float)$x); echo '<br>'; var_dump((boolean)$x);echo'<br>'; var_dump((string)$x);echo "<br>"; var_dump($x);echo "<br>"; var_dump(floatval($x)); echo '<br>'; var_dump(intval($x)); echo '<br>'; var_dump($x);echo "<br>"; ?> 2. Permanent type casting : This can be done by using pre-defined key-word set type.which hold two arguments Syntax : set type (var name,’int’); Ex : Permanent type casting.php <?php echo '<h1>Permanent Type Casting</h1>'; $x = "10.254Kgs";
  • 73. 73 settype($x,'float'); var_dump($x);echo "<br>"; settype($x,'int'); var_dump($x);echo "<br>"; settype($x,'boolean'); var_dump($x);echo "<br>"; settype($x,'int'); var_dump($x);echo "<br>"; var_dump($x);echo "<br>"; settype($x,'float'); var_dump($x);echo "<br>"; ?> Type juggling : conversion of data types by using expression to another data types are known as type juggling. Ex : typejuggling.php <?php echo 'true + true : ',true+true,'<br>'; if(null){ echo "Printed"; } else { echo "Not Printed";
  • 74. 74 } ?> Variable validation function : i) Isset : Isset of variables will check with the variable initialize or not and return Boolean ii) empty(var name) : empty function will check the variable whether it is null or not and return Boolean iii) Unset (var name) : This function will remove the variable (or) delete the variable iv) get type(var name) : This function will let us know the argument data type in the form of string ,this should be used because the coming variable would be depreciated. Ex : variable_validation.php <?php $x = 10; var_dump($x);echo '<br>'; var_dump(isset($x)); var_dump(isset($a));echo '<hr>'; $z = ''; var_dump(empty($z)); var_dump(empty($y)); $k = 10;echo '<br>'; var_dump(gettype($k));
  • 75. 75 unset($x); var_dump(isset($x)); ?> Data Types : Php supports mainly 8 kinds of data types among which four are stable data types, two are compound data types and another two are special data types a)Stable data types : i) int (or) integer ii) Float (or) real (or) decimal iii) Boolean data types iv) string data types i)int (or) integer : All non decimal values . range in between 2(32-1) to -2(32-1) Ex : <?php echo "<h1 align='center'>Stable Data types</h1>"; echo "<h2>Integer Data Type</h2>"; $x = 10; var_dump($x);echo '<br>'; $x = (pow(2,32-1)-1); var_dump($x); echo '<br>';
  • 76. 76 $judge = 2147483647; var_dump($judge); ?> ii) Float (or) real (or) decimal : All decimal values. Range in between 10(38) to 10(-38) Ex : <?php echo "<h2>Float Data Type</h2>"; $a = 10.25; var_dump($a);echo '<br>'; ?> iii) Boolean data types : Boolean data types return the values in the form of true (or) false Ex : <?php echo "<h2>Boolean Data Type</h2>"; $a = false; var_dump($a); ?> iv) String data types : Collection of characters enclose in between single (or) double cotations are known as string data types.
  • 77. 77 Ex : <?php echo "<h2>String Data Type</h2>"; $x = 10; echo '<br>The Value of $x is ',$x,'<br>'; echo "The Value of $x is :$x"; $name = "Rajesh"; echo '<br>my name is $name <br>'; echo "my name is $name <br>"; $x = 10; $y = 20; echo 'The value of $x+$y = ',$x+$y,'<br>'; echo "The value of $x+$y = ",$x+$y,'<br>'; ?> b)Compound data types : Compound data types again two types 1. Array data type 2. Object data type 1. Array data type : Array data type which can hold more than one value. In php we have mainly 3 kinds of arrays i) Numerical array ii) Associative array
  • 78. 78 iii) Mixed array Declaring an array in php can be done by two types  array as the function  array as a square bracket i) Numerical array : A numeric array stores each array element with a numeric index. There are two methods to create a numeric array.  In the following example the index are automatically assigned (the index starts at 0): $cars=array("Saab","Volvo","BMW","Toyota");  In the following example we assign the index manually: $cars[0]="Saab"; $cars[1]="Volvo"; $cars[2]="BMW"; $cars[3]="Toyota"; Ex : <?php $cars[0]="Saab"; $cars[1]="Volvo"; $cars[2]="BMW"; $cars[3]="Toyota"; echo $cars[0] . " and " . $cars[1] . " are Swedish cars."; ?> ii) Associative array : An associative array, each ID key is associated with a value.
  • 79. 79 When storing data about specific named values, a numerical array is not always the best way to do it. With associative arrays we can use the values as keys and assign values to them. Example 1 In this example we use an array to assign ages to the different persons: $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); Example 2 This example is the same as example 1, but shows a different way of creating the array: $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34"; The ID keys can be used in a script: <?php $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34"; echo "Peter is " . $ages['Peter'] . " years old."; ?> The code above will output: Peter is 32 years old. iii) Mixed array : Mixed array is nothing but combination of numerical & associative array is known as mixed array.
  • 80. 80 Ex : mixedarrays.php <?php $a = array("Name"=>"Rajesh","Age"=>30); print_r($a); echo '<hr>'; echo '<h1 align="center">Mixed Arrays</h1>'; define('A','ABC'); define('B','XYZ'); $c = 10; $d = 20; $g = array(0=>10,1=>20,'Name'=>'Raj','Age'=>30,5=>500,5.55=>600,- 9=>'Negative value',true=>200,false=>200,''=>'Empty Value',NULL=>'Null Value',A=>B,$c=>$d); echo '<pre>'; print_r($g); echo '</pre>'; ?> 2. Object data type : Object is an instance of class.Class can be denoted with in class name. Collection of variables and functions are known as class.For Calling class we should create an object then that particular variable is known as object variable.
  • 81. 81 Ex : <?php echo "<h2>Object Data Type</h2>"; class A{ public $x = 10; public $a = 20; function test(){ echo 'A test Function called<br>'; } } $b = new A; var_dump($b); echo '<br>Public Value $x = ',$b->x,$b->test(),'<br>'; ?> Special data types : Special data types are again two types i) Resource data types ii) Null data types i) Resource data types : Resource data type is calling an external variable value into another variable using (&) resource variable.
  • 82. 82 ii) Null data types : This is the pre-defined key-word. When a variable not initialize and by asking through printing method. This will result in null value. Ex : <?php echo "<h1 align='center'>Special Data types</h1>"; echo "<h2>Reference Data Type</h2>"; $x = 10; $y = $x; echo 'The Value of $x = ',$x,'<br>The Value of $y = ',$y,'<br>'; $x = 12; echo 'The Value of $x = ',$x,'<br>The Value of $y = ',$y,'<br>'; $y = 'Rajesh'; echo 'The Value of $x = ',$x,'<br>The Value of $y = ',$y,'<hr>'; echo "<h2>Resourse Data Type</h2>"; $a = 10; $b = &$a; echo 'The Value of $a = ',$a,'<br>The Value of $b = ',$b,'<br>'; $a = 'Raj'; echo 'The Value of $a = ',$a,'<br>The Value of $b = ',$b,'<br>'; $b = 'Amith'; echo 'The Value of $a = ',$a,'<br>The Value of $b = ',$b,'<br>';
  • 83. 83 echo "<h2>Null Data Type</h2>"; var_dump($z); ?> Constant : Define : Define is the pre-defined key-word in php. This will take two arguments. The first argument being the constant identifier which identifier its second argument value. We can pass third argument as Boolean to make case in-sensitive Ex : constant.php <?php define('x',10,true); echo x,'<br>'; echo X; echo '<hr>'; define('url','http://www.socialhub.com',true); echo uRl,'/register.php'; echo '<hr>'; define('SITE_NAME','http://www.socialhub.in-hyderabad','Social Hub'); ?> <h1>About us</h1> we at <?php echo SITE_NAME;?> are in training ........ <h1>Contact Us</h1>
  • 84. 84 <?php echo SITE_NAME;?> street ...... <h1>FAQ</h1> what we do at <?php echo SITE_NAME; ?> Conditions : Conditional statements are used to perform different actions based on different conditions a)If condition : IN PHP IN PERL If (cond) if (cond) : { //code //code else if (code) : } //code else if (cond) else (cond) : { //code //code end else if ; }
  • 85. 85 else (cond) { //code } b)Switch condition : Syntax : switch (cond) : switch (cond): { | Case1 : | //code | Break; | Case2: //code | Break; end switch; | | Default: //code }
  • 86. 86 Ex : <html> <body> <?php $x=1; switch ($x) { case 1: echo "Number 1"; break; case 2: echo "Number 2"; break; case 3: echo "Number 3"; break; default: echo "No number between 1 and 3"; } ?> </body> </html> c)While condition : The while loop executes a block of code while a condition is true Syntax: While (cond) while (cond): { //code inc/dec //const code inc/dec endwhile }
  • 87. 87 Ex: <html> <body> <?php $i=1; while($i<=5) { echo "The number is " . $i . "<br />"; $i++; } ?> </body> </html> d)Do-while condition : The do-while statement will always execute the block of code once, it will then check the condition, and repeat the loop while the condition is true. Syntax : Do do: { //code Inc/dec //code enddo while(cond); } While (cond) Example : The example below defines a loop that starts with i=1. It will then increment i with 1, and write some output. Then the condition is checked, and the loop will continue to run as long as i is less than, or equal to 5: <html> <body>
  • 88. 88 <?php $i=1; do { $i++; echo "The number is " . $i . "<br />"; } while ($i<=5); ?> </body> </html> e)For loop : Loops execute a block of code a specified number of times, or while a specified condition is true. The for loop is used when you know in advance how many times the script should run. Syntax : For(initialize;cond;inc/dec) //code end for Example : The example below defines a loop that starts with i=1. The loop will continue to run as long as i is less than, or equal to 5. i will increase by 1 each time the loop runs: <html> <body> <?php for ($i=1; $i<=5; $i++) { echo "The number is " . $i . "<br />"; } ?> </body> </html>
  • 89. 89 f)for each : for each is usefull for all non-sequence data of an array. Associative array ,numerical array object data of an array. The general syntax is foreach (arrayName as arr[value])) { echo arr [value]; } Another syntax is foreach (arrayname as key=>value) { echo key’-‘value (or) echo “key-value”; } Ex : foreach.php <?php $a = array("Name"=>"Rajesh","Age"=>30); /*foreach(arrayname as value){ echo arr[value]; }*/ foreach($a as $v){ echo $v,'<br>'; }echo '<hr>'; /*foreach(arrayname as key=>value){ echo key,' - ',value; }*/ foreach($a as $k=>$v){
  • 90. 90 echo "$k - $v<br>"; //echo $k,' - ',$v,'<br>'; } ?> Functions : Functions are case in-sensitive.Once function can be declare con’t be re-declare in the program. The real power of PHP comes from its functions. In PHP, there are more than 700 built-in functions. To keep the script from being executed when the page loads, you can put it into a function. A function will be executed by a call to the function. You may call a function from anywhere within a page.  Give the function a name that reflects what the function does  The function name can start with a letter or underscore (not a number) Syntax: function function name (arg) { //code Return value } There are mainly 8 kinds of functions in php
  • 91. 91 1. Conditional Function : A function which is enclose inside condition is considered as conditional function Ex : conditional.php <?php if(false){ function test(){ echo "I am a Conditional Function <br>"; } } @test(); 2. Variable Function : When a function name is told In variable. Variable can be used for excuting the function in a place of function name Ex : variables.php ?php function test(){ echo "I am a Variable Function <br>"; } test(); $a = 'test'; echo $a;echo '<br>'; $a(); $a(); 3. Function Function : Function is define inside another function is called as function-function.
  • 92. 92 Ex : function's function.php <?php Function parent f(){ echo “iam write the function function<br>”; If(!function_exists(childF)) { function child F() { echo “I need some one to open parent file for me to excute<br>”; } } } Parent F(); Child F(); Parent F()’ ?> 4. Function with arguments : Function can be defined with one (or) more arguments. If arguments are not passed then it creates warning in the program Ex : <?php function test($x,$y){ echo 'The Value of $x = ',$x,'<br>'; echo 'The Value of $y = ',$y,'<br>'; }
  • 93. 93 test('Raj','Kiran'); test(10,20); test('Amith'); test(); ?> 5. default argument : A function at the time of a declaration if argument are assign with some values they will be treated as optional (or) default argument value and they can be passed with value (or) can left without passing the value. Works at the side default argument must be passing last in the program at the argument list Ex : <?php function test($x=10,$y=20){ echo 'The Value of $x = ',$x,'<br>'; echo 'The Value of $y = ',$y,'<br>'; } test(100,200); test('Raj','Kiran'); test(); ?> 6. Overloaded argument : A function can be define with argument (or) that the defined arguments they are still acknowledge inside the function using various pre-defined function i) func_num_args() : return the total number of arguments which are passed in the function
  • 94. 94 ii) func_get_args() : return the array with all the arguments with the function iii) func_get_args(position) : return the argument value at the specified position Ex : <?php function test(){ echo "<h1>Overloaded Concept</h1>"; echo 'The Overloaded Length = ',func_num_args(),'<br>'; print_r(func_get_args()); echo '<hr>'; for($i=0;$i<func_num_args();$i++){ echo 'Index at : ',$i,' - ',func_get_arg($i),'<br>'; } echo '<hr><h1>For Each Method</h1>'; $y = func_get_args(); foreach($y as $k=>$v){ echo "$k => $v<br>"; } } test(10,20,'Rajesh'); 7. Function with Return value : Return key-word can be stop the execution of the function.Return key-word can optionally followed with a value which is return variable.Whenever a function is valid another one value con’t be passed after the return statement multiple value con’t be club as array (or) object and con’t be return wherever a function is called.
  • 95. 95 Ex : <?php function test(){ echo "This is Return Information<br>"; //return 10; echo "I am second info<br>"; return = 82; echo "I am second info<br>"; } test(); $y = test(); echo $y; //echo $y; 8. i) arguments passed by value : When an argument passed by value any change for the value inside the function owned be reflected in the variable outside the function ii) Arguments passed by reference : When an argument passed by resource and change for the inside with be refer to the variable outside the function Ex : <?php function test($x,&$y){ $x +=2; $y +=10; // $y = $y+10; echo 'The Value of $x = ',$x,'<br>';
  • 96. 96 echo 'The Value of $y = ',$y,'<br>'; } $a = 5; $b = 10; echo '$a = ',$a,'<br>';//5 echo '$b = ',$b,'<br>';//10 test($a,$b); echo '$a = ',$a,'<br>';//5 echo '$b = ',$b,'<br>';//10 ?> Built-in Functions : a)Math Functions : Ex : <?php echo 'Math Pi Value = ',M_PI,'<br>'; echo 'Math Pi Value = ',M_PI_2,'<br>'; echo 'Math Pi Value = ',M_PI_4,'<br>'; echo 'Eulers Constant = ',M_E,'<br>'; echo 'SQRT 2 = ',M_SQRT2,'<br>'; echo 'SQRT 2 = ',M_SQRT1_2,'<br>'; echo 'Log of 2 = ',log(2),'<br>'; echo 'Log base 10 of 2 = ',log10(2),'<br>'; echo 'Absolute Value = ',abs(-9),'<br>'; echo 'Exponent of 1 = ',exp(2),'<br>';
  • 97. 97 echo 'pi() = ',pi(),'<br>'; echo 'ceil value = ',ceil(2.1111),'<br>'; echo 'Floor Value = ',floor(2.9999),'<br>'; echo 'round = ',round(2.51458),'<br>'; echo 'round = ',round(2.51558,2),'<br>'; echo 'rad2deg(M_PI) = ',rad2deg(M_PI),'<br>'; echo 'rad2deg(M_PI) = ',rad2deg(M_PI_2),'<br>'; echo 'rad2deg(M_PI) = ',rad2deg(M_PI_4),'<br>'; echo 'deg2rad = ',deg2rad(180),'<br>'; echo 'sin 90 = ',sin(M_PI_2),'<br>'; echo 'tan 45 = ',tan(M_PI_4),'<br>'; echo 'hypot value = ',hypot(3,4),'<br>'; echo 'rand(min,max) = ',rand(100,1000),'<br>'; echo 'min value = ',min(10,20,30),'<br>'; echo 'max Value = ',max(2.999,2.998),'<br>'; ?> b)Date & Time Functions : Date : date is the pre-defined constant in php. It will generate current date according to the number of arguments passed. Mktime : Which can have arguments (hr, min, sec, month, day, year) unique time stamp. Check date() : Let us known the validate in a year j----> represents day of the month without leading zeros l---->view letter represents of the day of the way L---> whether it’s a leap year (or) not
  • 98. 98 W---> week number of year weeks starts from Monday w----> numerical represents of day of the way 0 for Monday through 6 for Saturday S---> English original safix for the day of the month two character ex: -st ,nd, rd,th F----> a full representation of the month such as January (or) March M---> short representation of the month such as jan (or) mar m---> numerical representation of the month with leading zero’s means 0-12 n---> numerical representation of month without zero’s which is 1-12 d---> number of days given in a month 28 (or) 31 y---> two digits representation of a year Y---> it is representation of the full year Time : Number of milliseconds sec right from unique time stamp a---> lowercase ante meridiem and post meridiem A---> uppercase ante meridiem and post meridiem B---> swatch internet time g---> 12- hours format of an hour without leading zeros G---> 24- hour format of an hour without leading zeros h---> 12- hours format of an hour with leading zeros H--->24- hours format of an hour with leading zeros i---> minutes with leading zero’s s---> seconds with leading zero’s u---> microseconds (added in php 5.2.2)
  • 99. 99 Ex : <?php echo 'Time zone set to : ',@date_default_timezone_get(),'<br>'; date_default_timezone_set('America/Denver'); echo 'Time zone set to : ',@date_default_timezone_get(),'<br>'; echo 'Today Date : ',@date("M-dS-Y, h:i:s a"),'<br><hr>'; date_default_timezone_set('America/Los_Angeles'); echo 'Time zone set to : ',@date_default_timezone_get(),'<br>'; echo 'Today Date : ',@date("M-dS-Y, h:i:s a"),'<br><hr>'; date_default_timezone_set('Asia/Calcutta'); echo 'Time zone set to : ',@date_default_timezone_get(),'<br>'; echo 'Today Date : ',@date("M-dS-Y, h:i:s A"),'<br><hr>'; var_dump(checkdate(02,29,1975)); echo '<hr>No of milliseconds from Unix time Constant ',time(),'<br>'; echo '<hr>Feature Date & time <br>'; echo 'Event is on : ',(date("M-dS-Y, h:i:s a",mktime(7,9,52,8,23,2012))),'<br><hr>'; echo date('Y'); ?> c)Array built-in Functions : <?php $a = array(10,20,30); function r($arr,$func=''){ if(!empty($func)){
  • 100. 100 echo "<h2 align='center'><u>$func</u></h2>"; } foreach($arr as $k=>$v){ echo "$k = $v<br>"; } echo '<hr>'; } echo 'Array count = ',count($a),'<br>'; echo 'Size of = ',sizeof($a),'<br>'; echo 'Sum of Array = ',array_sum($a),'<br>'; echo 'Product of Array = ',array_product($a),'<br>'; $a = array('Name'=>'Rajesh','Age'=>30,'Status'=>'Active','Email'=>'Raj@g mail.com','Gender'=>'Male'); r($a,'Normal Array'); $b = array_change_key_case($a,CASE_UPPER); r($b,'Upper Case'); $b = array_change_key_case($a,CASE_LOWER); r($b,'Lower Case'); $b = array_flip($a); r($b,'Array Flip'); $b = array_change_key_case(array_flip($a),CASE_UPPER); r($b,'Array Flip Values'); $a = array('Doctor','Fruit','Software'); $b = array('Patient','Orange','PHP');
  • 101. 101 r(array_combine($a,$b),'Array Combine'); $a = array('Name'=>'Rajesh','Age'=>30,'Status'=>'Active','Email'=>'Raj@g mail.com','Gender'=>'Male'); echo '<h2 align="center">Array Chunk</h2>'; $b = array_chunk($a,3); echo '<pre>'; print_r($b); echo '</pre>'; $a = array(10,20,30); $b = array(10,20,40,50); r(array_merge($a,$b),'Array Merge'); r(array_intersect($a,$b),'Array Intersect'); r(array_diff($a,$b),'Array Diff'); $a = array('raj@gmail.com','amith@gmail.com','rohan@gmail.com','sumit @gmail.com','raj@gmail.com'); r(array_unique($a),'Array Unique'); r(array_reverse($a),'Array Reverse'); $a = array(10,20,30); array_unshift($a,5); r($a,'Unshift Method'); array_shift($a); r($a,'shift Method'); array_push($a,40); r($a,'Push Method');
  • 102. 102 array_pop($a); r($a,'Pop Method'); $ns = $ss = $as = $ks = array('Name'=>'Rajesh','Age'=>30,'Status'=>'Active','Email'=>'Raj@g mail.com','Gender'=>'Male'); r($ns,'Normal Array'); sort($ss); r($ss,'Sorted Array'); rsort($ss); r($ss,'Reverse Sort Array'); asort($as); r($as,'Associative Sort Array'); arsort($as); r($as,'Associative Reverse Sort Array'); ksort($ks); r($ks,'Key Sort Method'); krsort($ks); r($ks,'Key Sort Reverse Method'); echo "<h2 align='center'>array_key_exists , array_search , in_array</h2>"; $a = array('Name'=>'Rajesh','Age'=>30,'Status'=>'Active','Email'=>'Raj@g mail.com','Gender'=>'Male'); echo 'Do i have Email Feild : ',var_dump(array_key_exists('Gender',$a)),'<br>'; echo 'Do we have Value with some : ',var_dump(array_search(30,$a)),'<br>';
  • 103. 103 echo 'Do we have Value with some : ',var_dump(in_array('Male',$a)),'<br>'; $a = array('Name'=>'Rajesh','Age'=>30,'Status'=>'Active','Email'=>'Raj@g mail.com','Gender'=>'Male'); r(array_keys($a),'Array Keys Calling'); r(array_values($a),'Array Value Calling'); $str = 'Hey i am from India & my name is Praveen'; $b = explode(" ",$str); //print_r($b);echo '<br>'; echo 'The Length of your total Words = ',count($b),'<br><hr>'; for($i=0;$i<count($b);$i++){ echo 'The index at ',$i,' = ',$b[$i],'<br>'; } $a = array('raj@gmail.com','amith@gmail.com','raju@gmail.com','suresh @gmail.com','raj@gmail.com','amith@gmail.com','raju@gmail.com',' suresh@gmail.com'); print_r($a); $b = implode(',',$a); <br><br> To : <input type='text' name='name' value='<?php echo $b;?>' size='60'/> <hr> <?php $a = array('born','child','teen','father','dead'); r($a,'Normal Array');
  • 104. 104 echo 'The Present Pointer is at : ',current($a),'<br>And the Key is at ',key($a),'<br>'; echo 'Next : ',next($a),'<br>'; echo 'The Present Pointer is at : ',current($a),'<br>And the Key is at ',key($a),'<br>'; echo 'Previous location : ',prev($a),'<br>'; echo 'The Present Pointer is at : ',current($a),'<br>And the Key is at ',key($a),'<br>'; echo 'End Value : ',end($a),'<br>'; echo 'The Present Pointer is at : ',current($a),'<br>And the Key is at ',key($a),'<br>'; echo 'The Present Pointer is at : ',current($a),'<br>And the Key is at ',key($a),'<br>'; echo 'Reset ',reset($a),'<br>'; echo 'The Present Pointer is at : ',current($a),'<br>And the Key is at ',key($a),'<hr>'; $a = array('Name'=>'Rajesh','Age'=>30); r(Each($a),'Each Method'); r(Each($a),'Each Method'); $a = array('ram','processor','computer'); list($gb,$intel,$dell) = $a; echo "$gb & $intel together makes $dell faster<br><hr>"; $str = "write some large text matter."; echo $str,'<br><hr>'; echo '<h2>Wordwrap</h2>'; echo wordwrap($str,20,'<br>',true); ?>
  • 105. 105 d)String built-in Functions : <?php echo '<h2>'; $str = "lamp institute"; echo "Normal String = ",$str,'<br>'; echo "Length of String = ",strlen($str),'<br>'; echo "To Upper Case = ",strtoUpper($str),'<br>'; echo "To Lower Case = ",strtoLower($str),'<br>'; echo "Upper case First Word = ",ucfirst($str),'<br>'; echo "Upper case words = ",ucwords($str),'<br>'; echo 'Reverse = ',strrev($str),'<br>'; echo '<hr>'; echo 'Position of str = ',strpos($str,'t'),'<br>'; echo 'last Position of str = ',strrpos($str,'t'),'<br>'; echo 'Postion of str after t again = ',strpos($str,'t',9),'<br>'; echo 'Position insensitive = ',stripos($str,'lamp'),'<br>'; echo 'last position at t insensitive = ',strripos($str,'T'),'<br>'; echo 'strstr will extract the entire string : ',strstr($str,"In"),'<br>'; echo 'strstr will extract the entire string : ',stristr($str,"in"),'<br>'; $name = 'Rajesh Kumar'; echo "substr = ",substr($name,0),'<br>'; echo "substr = ",substr($name,7,4),'<br>'; echo "substr = ",substr($name,-5,-1),'<br>'; $url = 'http://www.google.com?status=active';
  • 106. 106 $url .= '&'; echo 'substr = ',substr($url,0,-1),'<br>'; echo 'replace = ',str_ireplace('lamp','Apache',$str),'<br>'; $a = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX YZ0123456789'; echo str_shuffle($a),'<hr>'; echo substr(str_shuffle($a),0,12); echo '<hr>'; $name = "O'henry"; echo $name,'<br>'; echo addslashes($name),'<br>'; echo stripslashes('O'henry'),'<br>'; echo strip_tags("<b><i>Hi i am not feeling well</i></b>"); echo '<hr>';echo '<h2>'; $pwd = 'computer'; echo 'Original Name : ',$pwd,'<br>'; echo '<h1 align="center">One Way Encrypt</h1>'; echo 'Encrypt with MD5 = ',md5($pwd),'<br>';//32 char value echo 'Encrypt with MD5 strict = ',md5($pwd,true),'<br>';//16 bit binary format echo 'Encrypt with sha1 = ',sha1($pwd),'<br>';//40 char vlaue echo 'Encrypt with sha1 strict= ',sha1($pwd,true),'<br>';//20 binary vlaue echo 'Crypt = ',crypt($pwd),'<br>'; echo 'crypt salt = ',crypt($pwd,'d4'),'<br>';
  • 107. 107 echo '<h1 align="center">Encrypt & Decrypt Method</h1>'; echo 'encrypt = ',base64_encode($pwd),'<br>'; echo 'decrypt = ',base64_decode('Y29tcHV0ZXI='),'<br>'; echo '<h1 align="center">Url Encode & Decode</h1>'; $url = 'http://www.lamp.com?status=success&id=7&pid=20'; echo 'Original url = ',$url,'<br>'; echo 'encode = ',urlencode($url),'<br>'; echo 'decode = ',urldecode('http%3A%2F%2Fwww.lamp.com%3Fstatus%3Dsuccess %26id%3D7%26pid%3D20'),'<br><hr>'; echo '<pre>'; $name = " Rajesh "; echo 'My name is :',$name,'<br>'; echo 'My name is :',rtrim($name),'<br>'; echo 'My name is :',ltrim($name),'<br>'; echo 'My name is :',trim($name),'<br>'; echo '</pre>'; ?> PATH : FILE : The full path and filename of the file. If used inside an include, always contains an absolute path with some links LINE : The current line number of the file. DIR : The directory of the file. Realpath : Returns absolute pathname Basename : Returns filename component of path
  • 108. 108 Ex : <?php echo "File Information : ",__FILE__,'<br>'; echo "Base Name : ",basename(__FILE__),'<br>'; echo "Directory Name : ",dirname(__FILE__),'<br>'; echo "Directory Name : ",__dir__,'<br>'; echo "real Path : ",realpath(__FILE__),'<br>'; //echo "real Path : ",realpath('../..'),'<br>'; echo "Line NO : ",__LINE__,'<br>'; echo '<hr>'; $a = pathinfo(__FILE__); //print_r($a); foreach($a as $k=>$v){ echo $k,' = ',$v,'<br>'; } ?> e)File Functions : 1) stat(file path) : This function Return an array with file information 2)is_file(file path) : Checks wheather the file exist or not & Returns Boolean value. 3)file_get_contents(file Path) : Returns the file content as a string. 4)file_put_contents(fiel path,data) : Writes the content to the file overwriting old content and if file does not exists, creates a new file & adds the content.This function is introduced in 5th version.
  • 109. 109 5)file(file path) : Returns the file content as an array with each line in the file at a particular index position. 6)filectime(path) : Creates the time of the file. 7)fileatime(file path) : Last access time of the path file. 8)filemtime(file path) : Last modified time of the file. 9)unlink(file path) : Removes the file from the location. 10)filesize(file path) : Returns the size of the file in bites 11)filetype(file Path) : Returns the type of the file (dir or file) 12)fopen(file path,mode) : Opens the file in the specified mode and returns a file handler for handling the file. 13)fread(file handler, size) : Reads the file content from the current file handler position upto the specified size. 14)$fp -> file Pointer ..The internal handler which is used for handling the file. 15)fgetc(file handler) : Reads a single char in the string. 16)fgets(file handler) : Reads a single line from the file.. 17)fgetss(file handler) : Reads a single line from the file stripping of html tags in the file. 18)fwrite(file handler) : This function is used to write the content to the file 19)ftell(file handler) : Returns the file handler position in the file 20)fseek(file handler) : Moves the file handler to the specified position in the file 21)fclose(file handler) : Closes the File handler connection. List of Modes : r --> Read Mode r+ --> Read and Write.
  • 110. 110 w --> Write Mode w+ --> Write & Read. a --> Append (also writing but without overwriting files) a+ --> append & read. x --> Creates a new file & write.. x+ --> Creat a new file for write and read. rb,rb+,wb,wb+,ab,ab+,xb,xb+ are the modes to be used for binary files. Examples for above specified actions : -----fileput.php <?php $file = 'a.txt'; file_put_contents($file,str_repeat("MOd ",5)); ?> -----create.php <?php $file = 'c.txt'; $fp = fopen($file,"x"); fwrite($fp," Created"); fclose($fp); if(is_file($file)){ echo file_get_contents($file); } ?>
  • 111. 111 -----write.php <?php $file = 'b.txt'; $fp = fopen($file,"w"); fwrite($fp,"Modified"); fclose($fp); if(is_file($file)){ echo file_get_contents($file); } ?> -----read.php <?php $file = 'test.txt'; $fp = fopen($file,"r"); echo "Pos : ",ftell($fp),'<br>'; echo fread($fp,3),'<br>'; echo "Pos : ",ftell($fp),'<br>'; echo fgetc($fp),'<br>'; echo "Pos : ",ftell($fp),'<br>'; echo fgets($fp),'<br>'; echo fgets($fp),'<br>'; echo 'Pos : ',ftell($fp),'<Br>'; echo fgets($fp),'<br>'; fseek($fp,35);
  • 112. 112 echo fgetss($fp),'<br>'; fclose($fp); ?> -----func.php <?php $file = 'test.txt'; var_dump(is_file($file)); echo '<br>'; echo "size : ",filesize($file),'<br>'; echo "Type : ",filetype($file),'<br>'; echo "Created : ",date("d-m-y h:i:s",filectime($file)),'<br>'; echo "Accessed : ",date("d-m-y h:i:s",fileatime($file)),'<br>'; echo "Modified : ",date("d-m-y h:i:s",filemtime($file)),'<br>'; echo file_get_contents($file),'<br>'; echo "<pre>"; print_r(file($file)); echo '<br>'; print_r(stat($file)); ?> -----append.php <?php $file = 'b.txt'; $fp = fopen($file,"a"); fwrite($fp,"Append");
  • 113. 113 fclose($fp); if(is_file($file)){ echo file_get_contents($file); } ?> -----unlink.php <?php $file = 'a.txt'; unlink($file); ?> f)Directory Functions: 1)getcwd() : Current working directory, 2)chdir(path) : Change current working dir to argumented path. 3)is_dir(path) : Checks wheather the argumented dir exist or not and return Boolean value. 4)mkdir(dirname) : Makes a directory on the current working location. 5)rename(old name,new name): Changes the name of the directory. 6)rmdir(dir name) : Removes the directory. 7)scandir(path) : Scan the directory and return the directory content as an array. Returns an array with related path information. -----getcwd.php <?php echo 'Cwd : ',getcwd(),'<br>'; $a = scandir('.',0);
  • 114. 114 foreach($a as $k=>$v){ echo "$k == $v<br>"; } chdir('..');echo '<hr>'; echo 'Cwd : ',getcwd(),'<br><hr>'; $a = scandir('.',0); foreach($a as $k=>$v){ echo "$k == $v<br>"; } ?> -----mkdir.php <?php $dir = 'test'; if(!is_dir($dir)){ mkdir($dir); echo "Directory is created"; } else { echo "Directory already exists"; } ?> -----rename.php <?php $dir = 'test'; $new = "modified";
  • 115. 115 if(is_dir($dir)){ rename($dir,$new); echo "Directory name is $new"; } else { echo "Directory does not exists"; } ?> -----rmdir.php <?php $new = "modified"; if(is_dir($new)){ rmdir($new); echo "Directory is removed"; } else { echo "Directory does not exists"; } ?> scandir.php <?php echo '<pre>'; var_dump(scandir('.')); ?>
  • 116. 116 Super Globals : Difference between GET and POST : GET POST 1.GET data transfers through URL. POST data is send through request headers 2.GET is insecure POST is secure 3.File cannot be transfered using GET Files can be transfered 4.Limited data can be send based on length We can send huge data(8MB) which can be scaled of URL supported by browser(2KB). up by using POST_MAX_SIZE 5.It is fast It is not as fast as GET. 6.$_GET is used for accessing $_POST is used for accessing the GET parameters the POST parameters GET Ex : -----get.php <?php if(isset($_GET['submit'])){ echo 'Name : ',$_GET['fname'],'<br>'; echo 'Email Address : ',$_GET['email'],'<br>'; $gend = ($_GET['gender'] == 'm')?'Male':'Female'; echo 'Gender : ',$gend,'<br>'; }
  • 117. 117 echo '<hr>'; echo urldecode($_SERVER['QUERY_STRING']);echo '<hr><br>'; ?> -----get.html <form method='GET' action='get.php'> Name : <input type='text' name='fname' value=''><br> E-Mail : <input type='text' name='email' value=''><br> Gender : <input type='radio' name='gender' value='m'> Male <input type='radio' name='gender' value='f'> Female<br> <input type='submit' name='submit' value='Register !'> </form> POST Ex : -----post.php <?php if(isset($_POST['submit'])){ echo 'Name : ',$_POST['fname'],'<br>'; echo 'Email Address : ',$_POST['email'],'<br>'; $gend = ($_POST['gender']=='m')?'Male':'Female'; echo 'Gender : ',$gend,'<br>'; $a = $_POST['course']; echo $a,'<br><hr>'; print_r($a); } echo '<hr>'; echo 'The query string : ',$_SERVER['QUERY_STRING'],'<br>';
  • 118. 118 ?> -----post.html <form method='POST' action='post.php'/> Name : <input type='text' name='fname' value=''/><br> E-Mail : <input type='text' name='email' value=''/><br> Gender : <input type='radio' name='gender' value='m'/> Male <input type='radio' name='gender' value='f'/> Female <br> Hobbies : <br> <input type='checkbox' name='course[]' value='c'/> C-Language <br> <input type='checkbox' name='course[]' value='p'/> PHP <br> <input type='checkbox' name='course[]' value='j'/> Java <br> <input type='submit' name='submit' value='Register'/> </form> Server Variables : -----servervariables.php <?php echo 'Get Environment : ',getenv('os'),'<br>'; echo 'Environment Path : ',getenv('path'),'<br>'; echo '<hr>'; echo 'Document Root : ',$_SERVER['DOCUMENT_ROOT'],'<br>'; echo 'Http Host : ',$_SERVER['HTTP_HOST'],'<br>'; echo 'Referer : ',$_SERVER['HTTP_REFERER'],'<br>'; echo 'Method : ',$_SERVER['REQUEST_METHOD'],'<br>'; echo 'User Agent : ',($_SERVER['HTTP_USER_AGENT']),'<br>';
  • 119. 119 echo 'Name of Script : ',$_SERVER['SCRIPT_NAME'],'<br>'; echo 'Query String : ',$_SERVER['QUERY_STRING'],'<br>'; echo 'Remote Ip Address : ',$_SERVER['REMOTE_ADDR'],'<br>'; echo 'PHP Self : ',$_SERVER['PHP_SELF'],'<br>'; echo 'Request URL : ',$_SERVER['REQUEST_URI'],'<br>'; echo 'Script File Name : ',$_SERVER['SCRIPT_FILENAME'],'<br>'; ?> -----phpinfo.php <?php echo phpinfo(); ?>  Include_once and required _once : These both will include file very first time and if already file has been included this will not include for the second time.  Defference between include_once & include : Include and include _once will include the files. But if the path of the file is wrong include and include_once will generate the wrong message and rest of the code will be excuted. Required and required_once : If location of the path is given wrong this will through a wrong as well as path error and code gets halted or the execution will be stop. Ex : a.php <style> b{color:green;} </style> <b>I am included</b><br><hr> <?php
  • 120. 120 $a = 10; if(!function_exists('r')){ function r(){ echo 'I am in a.php and working fine<br>'; } } ?> b.php <?php include_once("a.php"); include("a.php"); include("a.php"); $b = 20; echo 'The Value of $a = ',$a,'<br>'; echo 'The Value of $b = ',$b,'<br>'; r(); ?> Headers : Headers are the information which are exchanged between client and server for every request and response. Headers are of two types. a) Request Headers. b) Response Headers. a) Request Headers : These are send from client to server.
  • 121. 121 HTTP Request : GET/php7/info.php HTTP/1.1 Host : localhost User_Agent : Mozilla/5.0 Accept : text/HTML, application/html Accept_encoding: gzip,deflate Connection : keep-alive keep-alive : 115 Accept_char : ISO-88591-1 utf-8;q=0.7 Ex : apache_request_headers() b) Response Headers : These are send from server to client. X-powered-by : php/5.3.1 keep_Alive : timeout=5,max=100 connection : Keep_Alive Transfer_Encoding : chunted content_type : text/html Ex : apache_response_headers() HTTP Methods : For every request from the client to server can be made through various HTTP methods like GET, POST, PUT, DELETE, HEAD Headers can be send from php program to the server. 1. headers_list() : Returns an array to the list of the headers which can be shared from server to client.
  • 122. 122 2. headers_sent() : Returns the boolean value above whether the headers were send to the client or not. 3.header("<name>:<value>") : Header function should be used in the page before any output is send to the page. Header functions are used for redirection and for sending the output and also for downloading of the files. Php content in different formats(content type like html,xhtml,images,pdf,flash,video etc). Ex : -----hrds.php <?php ob_start(); print_r(apache_request_headers()); echo '<hr>'; var_dump(headers_sent()); header("Name:Rajesh"); header("location:info.php"); print_r(headers_list()); echo '<hr>'; print_r(apache_response_headers()); ?> -----info.php <?php echo phpinfo(); ?>