Top Banner
Introduction to PHP 1 Introduction to PHP AIMS BBSYDP TRAINING JUNAID NAZIR [email protected]
37

Introduction to php

Dec 14, 2014

Download

Education

Anjan Banda

Introduction to php is helpful for web designing,and we will find it more easier by this realy good presentation.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to php

Introduction to PHP

1

Introduction to PHP

AIMS BBSYDP TRAINING

JUNAID NAZIR

junaidcomelearnsharecom

Introduction to PHP

Introduction to PHP

bull PHP is a server-side scripting language designed

for web development but also used as a general-

purpose programming language As of January 2013

PHP was installed on more than 240

million websites (39 of those sampled) and 21

million web servers[Originally created by Ramses

Lerdorf in 1994the reference implementation of PHP

is now produced by The PHP Group While PHP

originally stood for Personal Home Page it now

stands for PHP Hypertext Preprocessor a

recursive backronym

bull

2

Introduction to PHP

Introduction to PHP

bull PHP code can be simply mixed with HTML code or it can be

used in combination with various templating engines and web

frameworks PHP code is usually processed by a

PHP interpreter which is usually implemented as a web servers

native module or aCommon Gateway Interface (CGI)

executable After the PHP code is interpreted and executed the

web server sends resulting output to its client usually in form of

a part of the generated web page ndash for example PHP code can

generate a web pages HTML code an image or some other

data PHP has also evolved to include a command-line

interface (CLI) capability and can be used

in standalonegraphical applications

bull

3

Introduction to PHP

4

Introduction to PHP

bull PHP Hypertext Preprocessor

ndash Other Names Personal Home Page Professional Home

Page

bull Is a server side scripting language

ndash Capable of generating the HTML pages

bull HTML generates the web page with the static text

and images

bull However the need evolved for dynamic web based

application mostly involving database usage

Introduction to PHP

PHP FOUNDER

5

Introduction to PHP

Release History

6

Introduction to PHP

Release History

7

Introduction to PHP

8

CLIENT

WEB

SERVER

HTTP Request

(url)

ltHTMLgt

ltphp PHP code gt

ltHTMLgt

Gets Page

ltHTMLgt

ltBgtHelloltBgt

ltHTMLgt

Interprets the PHP code

Server response

Browser creates

the web page

Hello

Introduction to PHP

9

Why PHP bull there are no of server side scripting available like

ASP SSJS JSPhellip bull PHP involves

ndash simplicity in scripting (generally using the database)

ndash platform independence

bull PHP is

ndash primarily designed for web applications

ndash well optimized for the response times needed for web

applications

bull Is an open source

Introduction to PHP

10

PHP Language features

bull PHP language features such as control

structures operators variable types function

declaration classobject declaration are

almost similar to any compiled or interpreted

language such as C or C++

Introduction to PHP

11

PHP Data Type

bull Three basic data types ndash Integer

ndash Double

ndash String

bull More data types ndash Array

ndash Object

bull PHP is an untyped language ndash variables type can change on the fly

Introduction to PHP

12

PHP Block

bull PHP code block is embedded within the ltphp

and gt tags

bull When the server encounters the PHP tags it

switches from the HTML to PHP mode

bull There are four different ways to embed the

PHP code ndash ltphp echo(ldquoSome PHP coderdquo) gt

ndash lt echo(ldquoSome PHP coderdquo) gt

ndash ltSCRIPT Language=lsquophprsquogt echo(ldquoSome PHP coderdquo) ltSCRIPTgt

ndash lt echo(ldquoSome PHP coderdquo) gt

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 2: Introduction to php

Introduction to PHP

Introduction to PHP

bull PHP is a server-side scripting language designed

for web development but also used as a general-

purpose programming language As of January 2013

PHP was installed on more than 240

million websites (39 of those sampled) and 21

million web servers[Originally created by Ramses

Lerdorf in 1994the reference implementation of PHP

is now produced by The PHP Group While PHP

originally stood for Personal Home Page it now

stands for PHP Hypertext Preprocessor a

recursive backronym

bull

2

Introduction to PHP

Introduction to PHP

bull PHP code can be simply mixed with HTML code or it can be

used in combination with various templating engines and web

frameworks PHP code is usually processed by a

PHP interpreter which is usually implemented as a web servers

native module or aCommon Gateway Interface (CGI)

executable After the PHP code is interpreted and executed the

web server sends resulting output to its client usually in form of

a part of the generated web page ndash for example PHP code can

generate a web pages HTML code an image or some other

data PHP has also evolved to include a command-line

interface (CLI) capability and can be used

in standalonegraphical applications

bull

3

Introduction to PHP

4

Introduction to PHP

bull PHP Hypertext Preprocessor

ndash Other Names Personal Home Page Professional Home

Page

bull Is a server side scripting language

ndash Capable of generating the HTML pages

bull HTML generates the web page with the static text

and images

bull However the need evolved for dynamic web based

application mostly involving database usage

Introduction to PHP

PHP FOUNDER

5

Introduction to PHP

Release History

6

Introduction to PHP

Release History

7

Introduction to PHP

8

CLIENT

WEB

SERVER

HTTP Request

(url)

ltHTMLgt

ltphp PHP code gt

ltHTMLgt

Gets Page

ltHTMLgt

ltBgtHelloltBgt

ltHTMLgt

Interprets the PHP code

Server response

Browser creates

the web page

Hello

Introduction to PHP

9

Why PHP bull there are no of server side scripting available like

ASP SSJS JSPhellip bull PHP involves

ndash simplicity in scripting (generally using the database)

ndash platform independence

bull PHP is

ndash primarily designed for web applications

ndash well optimized for the response times needed for web

applications

bull Is an open source

Introduction to PHP

10

PHP Language features

bull PHP language features such as control

structures operators variable types function

declaration classobject declaration are

almost similar to any compiled or interpreted

language such as C or C++

Introduction to PHP

11

PHP Data Type

bull Three basic data types ndash Integer

ndash Double

ndash String

bull More data types ndash Array

ndash Object

bull PHP is an untyped language ndash variables type can change on the fly

Introduction to PHP

12

PHP Block

bull PHP code block is embedded within the ltphp

and gt tags

bull When the server encounters the PHP tags it

switches from the HTML to PHP mode

bull There are four different ways to embed the

PHP code ndash ltphp echo(ldquoSome PHP coderdquo) gt

ndash lt echo(ldquoSome PHP coderdquo) gt

ndash ltSCRIPT Language=lsquophprsquogt echo(ldquoSome PHP coderdquo) ltSCRIPTgt

ndash lt echo(ldquoSome PHP coderdquo) gt

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 3: Introduction to php

Introduction to PHP

Introduction to PHP

bull PHP code can be simply mixed with HTML code or it can be

used in combination with various templating engines and web

frameworks PHP code is usually processed by a

PHP interpreter which is usually implemented as a web servers

native module or aCommon Gateway Interface (CGI)

executable After the PHP code is interpreted and executed the

web server sends resulting output to its client usually in form of

a part of the generated web page ndash for example PHP code can

generate a web pages HTML code an image or some other

data PHP has also evolved to include a command-line

interface (CLI) capability and can be used

in standalonegraphical applications

bull

3

Introduction to PHP

4

Introduction to PHP

bull PHP Hypertext Preprocessor

ndash Other Names Personal Home Page Professional Home

Page

bull Is a server side scripting language

ndash Capable of generating the HTML pages

bull HTML generates the web page with the static text

and images

bull However the need evolved for dynamic web based

application mostly involving database usage

Introduction to PHP

PHP FOUNDER

5

Introduction to PHP

Release History

6

Introduction to PHP

Release History

7

Introduction to PHP

8

CLIENT

WEB

SERVER

HTTP Request

(url)

ltHTMLgt

ltphp PHP code gt

ltHTMLgt

Gets Page

ltHTMLgt

ltBgtHelloltBgt

ltHTMLgt

Interprets the PHP code

Server response

Browser creates

the web page

Hello

Introduction to PHP

9

Why PHP bull there are no of server side scripting available like

ASP SSJS JSPhellip bull PHP involves

ndash simplicity in scripting (generally using the database)

ndash platform independence

bull PHP is

ndash primarily designed for web applications

ndash well optimized for the response times needed for web

applications

bull Is an open source

Introduction to PHP

10

PHP Language features

bull PHP language features such as control

structures operators variable types function

declaration classobject declaration are

almost similar to any compiled or interpreted

language such as C or C++

Introduction to PHP

11

PHP Data Type

bull Three basic data types ndash Integer

ndash Double

ndash String

bull More data types ndash Array

ndash Object

bull PHP is an untyped language ndash variables type can change on the fly

Introduction to PHP

12

PHP Block

bull PHP code block is embedded within the ltphp

and gt tags

bull When the server encounters the PHP tags it

switches from the HTML to PHP mode

bull There are four different ways to embed the

PHP code ndash ltphp echo(ldquoSome PHP coderdquo) gt

ndash lt echo(ldquoSome PHP coderdquo) gt

ndash ltSCRIPT Language=lsquophprsquogt echo(ldquoSome PHP coderdquo) ltSCRIPTgt

ndash lt echo(ldquoSome PHP coderdquo) gt

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 4: Introduction to php

Introduction to PHP

4

Introduction to PHP

bull PHP Hypertext Preprocessor

ndash Other Names Personal Home Page Professional Home

Page

bull Is a server side scripting language

ndash Capable of generating the HTML pages

bull HTML generates the web page with the static text

and images

bull However the need evolved for dynamic web based

application mostly involving database usage

Introduction to PHP

PHP FOUNDER

5

Introduction to PHP

Release History

6

Introduction to PHP

Release History

7

Introduction to PHP

8

CLIENT

WEB

SERVER

HTTP Request

(url)

ltHTMLgt

ltphp PHP code gt

ltHTMLgt

Gets Page

ltHTMLgt

ltBgtHelloltBgt

ltHTMLgt

Interprets the PHP code

Server response

Browser creates

the web page

Hello

Introduction to PHP

9

Why PHP bull there are no of server side scripting available like

ASP SSJS JSPhellip bull PHP involves

ndash simplicity in scripting (generally using the database)

ndash platform independence

bull PHP is

ndash primarily designed for web applications

ndash well optimized for the response times needed for web

applications

bull Is an open source

Introduction to PHP

10

PHP Language features

bull PHP language features such as control

structures operators variable types function

declaration classobject declaration are

almost similar to any compiled or interpreted

language such as C or C++

Introduction to PHP

11

PHP Data Type

bull Three basic data types ndash Integer

ndash Double

ndash String

bull More data types ndash Array

ndash Object

bull PHP is an untyped language ndash variables type can change on the fly

Introduction to PHP

12

PHP Block

bull PHP code block is embedded within the ltphp

and gt tags

bull When the server encounters the PHP tags it

switches from the HTML to PHP mode

bull There are four different ways to embed the

PHP code ndash ltphp echo(ldquoSome PHP coderdquo) gt

ndash lt echo(ldquoSome PHP coderdquo) gt

ndash ltSCRIPT Language=lsquophprsquogt echo(ldquoSome PHP coderdquo) ltSCRIPTgt

ndash lt echo(ldquoSome PHP coderdquo) gt

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 5: Introduction to php

Introduction to PHP

PHP FOUNDER

5

Introduction to PHP

Release History

6

Introduction to PHP

Release History

7

Introduction to PHP

8

CLIENT

WEB

SERVER

HTTP Request

(url)

ltHTMLgt

ltphp PHP code gt

ltHTMLgt

Gets Page

ltHTMLgt

ltBgtHelloltBgt

ltHTMLgt

Interprets the PHP code

Server response

Browser creates

the web page

Hello

Introduction to PHP

9

Why PHP bull there are no of server side scripting available like

ASP SSJS JSPhellip bull PHP involves

ndash simplicity in scripting (generally using the database)

ndash platform independence

bull PHP is

ndash primarily designed for web applications

ndash well optimized for the response times needed for web

applications

bull Is an open source

Introduction to PHP

10

PHP Language features

bull PHP language features such as control

structures operators variable types function

declaration classobject declaration are

almost similar to any compiled or interpreted

language such as C or C++

Introduction to PHP

11

PHP Data Type

bull Three basic data types ndash Integer

ndash Double

ndash String

bull More data types ndash Array

ndash Object

bull PHP is an untyped language ndash variables type can change on the fly

Introduction to PHP

12

PHP Block

bull PHP code block is embedded within the ltphp

and gt tags

bull When the server encounters the PHP tags it

switches from the HTML to PHP mode

bull There are four different ways to embed the

PHP code ndash ltphp echo(ldquoSome PHP coderdquo) gt

ndash lt echo(ldquoSome PHP coderdquo) gt

ndash ltSCRIPT Language=lsquophprsquogt echo(ldquoSome PHP coderdquo) ltSCRIPTgt

ndash lt echo(ldquoSome PHP coderdquo) gt

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 6: Introduction to php

Introduction to PHP

Release History

6

Introduction to PHP

Release History

7

Introduction to PHP

8

CLIENT

WEB

SERVER

HTTP Request

(url)

ltHTMLgt

ltphp PHP code gt

ltHTMLgt

Gets Page

ltHTMLgt

ltBgtHelloltBgt

ltHTMLgt

Interprets the PHP code

Server response

Browser creates

the web page

Hello

Introduction to PHP

9

Why PHP bull there are no of server side scripting available like

ASP SSJS JSPhellip bull PHP involves

ndash simplicity in scripting (generally using the database)

ndash platform independence

bull PHP is

ndash primarily designed for web applications

ndash well optimized for the response times needed for web

applications

bull Is an open source

Introduction to PHP

10

PHP Language features

bull PHP language features such as control

structures operators variable types function

declaration classobject declaration are

almost similar to any compiled or interpreted

language such as C or C++

Introduction to PHP

11

PHP Data Type

bull Three basic data types ndash Integer

ndash Double

ndash String

bull More data types ndash Array

ndash Object

bull PHP is an untyped language ndash variables type can change on the fly

Introduction to PHP

12

PHP Block

bull PHP code block is embedded within the ltphp

and gt tags

bull When the server encounters the PHP tags it

switches from the HTML to PHP mode

bull There are four different ways to embed the

PHP code ndash ltphp echo(ldquoSome PHP coderdquo) gt

ndash lt echo(ldquoSome PHP coderdquo) gt

ndash ltSCRIPT Language=lsquophprsquogt echo(ldquoSome PHP coderdquo) ltSCRIPTgt

ndash lt echo(ldquoSome PHP coderdquo) gt

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 7: Introduction to php

Introduction to PHP

Release History

7

Introduction to PHP

8

CLIENT

WEB

SERVER

HTTP Request

(url)

ltHTMLgt

ltphp PHP code gt

ltHTMLgt

Gets Page

ltHTMLgt

ltBgtHelloltBgt

ltHTMLgt

Interprets the PHP code

Server response

Browser creates

the web page

Hello

Introduction to PHP

9

Why PHP bull there are no of server side scripting available like

ASP SSJS JSPhellip bull PHP involves

ndash simplicity in scripting (generally using the database)

ndash platform independence

bull PHP is

ndash primarily designed for web applications

ndash well optimized for the response times needed for web

applications

bull Is an open source

Introduction to PHP

10

PHP Language features

bull PHP language features such as control

structures operators variable types function

declaration classobject declaration are

almost similar to any compiled or interpreted

language such as C or C++

Introduction to PHP

11

PHP Data Type

bull Three basic data types ndash Integer

ndash Double

ndash String

bull More data types ndash Array

ndash Object

bull PHP is an untyped language ndash variables type can change on the fly

Introduction to PHP

12

PHP Block

bull PHP code block is embedded within the ltphp

and gt tags

bull When the server encounters the PHP tags it

switches from the HTML to PHP mode

bull There are four different ways to embed the

PHP code ndash ltphp echo(ldquoSome PHP coderdquo) gt

ndash lt echo(ldquoSome PHP coderdquo) gt

ndash ltSCRIPT Language=lsquophprsquogt echo(ldquoSome PHP coderdquo) ltSCRIPTgt

ndash lt echo(ldquoSome PHP coderdquo) gt

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 8: Introduction to php

Introduction to PHP

8

CLIENT

WEB

SERVER

HTTP Request

(url)

ltHTMLgt

ltphp PHP code gt

ltHTMLgt

Gets Page

ltHTMLgt

ltBgtHelloltBgt

ltHTMLgt

Interprets the PHP code

Server response

Browser creates

the web page

Hello

Introduction to PHP

9

Why PHP bull there are no of server side scripting available like

ASP SSJS JSPhellip bull PHP involves

ndash simplicity in scripting (generally using the database)

ndash platform independence

bull PHP is

ndash primarily designed for web applications

ndash well optimized for the response times needed for web

applications

bull Is an open source

Introduction to PHP

10

PHP Language features

bull PHP language features such as control

structures operators variable types function

declaration classobject declaration are

almost similar to any compiled or interpreted

language such as C or C++

Introduction to PHP

11

PHP Data Type

bull Three basic data types ndash Integer

ndash Double

ndash String

bull More data types ndash Array

ndash Object

bull PHP is an untyped language ndash variables type can change on the fly

Introduction to PHP

12

PHP Block

bull PHP code block is embedded within the ltphp

and gt tags

bull When the server encounters the PHP tags it

switches from the HTML to PHP mode

bull There are four different ways to embed the

PHP code ndash ltphp echo(ldquoSome PHP coderdquo) gt

ndash lt echo(ldquoSome PHP coderdquo) gt

ndash ltSCRIPT Language=lsquophprsquogt echo(ldquoSome PHP coderdquo) ltSCRIPTgt

ndash lt echo(ldquoSome PHP coderdquo) gt

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 9: Introduction to php

Introduction to PHP

9

Why PHP bull there are no of server side scripting available like

ASP SSJS JSPhellip bull PHP involves

ndash simplicity in scripting (generally using the database)

ndash platform independence

bull PHP is

ndash primarily designed for web applications

ndash well optimized for the response times needed for web

applications

bull Is an open source

Introduction to PHP

10

PHP Language features

bull PHP language features such as control

structures operators variable types function

declaration classobject declaration are

almost similar to any compiled or interpreted

language such as C or C++

Introduction to PHP

11

PHP Data Type

bull Three basic data types ndash Integer

ndash Double

ndash String

bull More data types ndash Array

ndash Object

bull PHP is an untyped language ndash variables type can change on the fly

Introduction to PHP

12

PHP Block

bull PHP code block is embedded within the ltphp

and gt tags

bull When the server encounters the PHP tags it

switches from the HTML to PHP mode

bull There are four different ways to embed the

PHP code ndash ltphp echo(ldquoSome PHP coderdquo) gt

ndash lt echo(ldquoSome PHP coderdquo) gt

ndash ltSCRIPT Language=lsquophprsquogt echo(ldquoSome PHP coderdquo) ltSCRIPTgt

ndash lt echo(ldquoSome PHP coderdquo) gt

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 10: Introduction to php

Introduction to PHP

10

PHP Language features

bull PHP language features such as control

structures operators variable types function

declaration classobject declaration are

almost similar to any compiled or interpreted

language such as C or C++

Introduction to PHP

11

PHP Data Type

bull Three basic data types ndash Integer

ndash Double

ndash String

bull More data types ndash Array

ndash Object

bull PHP is an untyped language ndash variables type can change on the fly

Introduction to PHP

12

PHP Block

bull PHP code block is embedded within the ltphp

and gt tags

bull When the server encounters the PHP tags it

switches from the HTML to PHP mode

bull There are four different ways to embed the

PHP code ndash ltphp echo(ldquoSome PHP coderdquo) gt

ndash lt echo(ldquoSome PHP coderdquo) gt

ndash ltSCRIPT Language=lsquophprsquogt echo(ldquoSome PHP coderdquo) ltSCRIPTgt

ndash lt echo(ldquoSome PHP coderdquo) gt

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 11: Introduction to php

Introduction to PHP

11

PHP Data Type

bull Three basic data types ndash Integer

ndash Double

ndash String

bull More data types ndash Array

ndash Object

bull PHP is an untyped language ndash variables type can change on the fly

Introduction to PHP

12

PHP Block

bull PHP code block is embedded within the ltphp

and gt tags

bull When the server encounters the PHP tags it

switches from the HTML to PHP mode

bull There are four different ways to embed the

PHP code ndash ltphp echo(ldquoSome PHP coderdquo) gt

ndash lt echo(ldquoSome PHP coderdquo) gt

ndash ltSCRIPT Language=lsquophprsquogt echo(ldquoSome PHP coderdquo) ltSCRIPTgt

ndash lt echo(ldquoSome PHP coderdquo) gt

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 12: Introduction to php

Introduction to PHP

12

PHP Block

bull PHP code block is embedded within the ltphp

and gt tags

bull When the server encounters the PHP tags it

switches from the HTML to PHP mode

bull There are four different ways to embed the

PHP code ndash ltphp echo(ldquoSome PHP coderdquo) gt

ndash lt echo(ldquoSome PHP coderdquo) gt

ndash ltSCRIPT Language=lsquophprsquogt echo(ldquoSome PHP coderdquo) ltSCRIPTgt

ndash lt echo(ldquoSome PHP coderdquo) gt

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 13: Introduction to php

Introduction to PHP

13

PHP Constants

bull values that never changes

bull Constants are defined in PHP by using the

define() function

ndash For eg

define(ldquoNCSTrdquo ldquoNational Centre for Software Technologyrdquo) bull defined() function says whether the constant exists

or not

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 14: Introduction to php

Introduction to PHP

14

PHP Variables

bull The variables in PHP are declared by

appending the $ sign to the variable name

ndash For eg

$company = ldquoNCSTrdquo $sum = 100

bull variablersquos data type is changed by the value that is assigned to the variable

bull Type casting allows to change the data type

explicitly

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 15: Introduction to php

Introduction to PHP

15

PHP Variables (cont) bull Rich set of functions for working with

variable

ndash For eg

bull gettype settype isset unset is_int intval etc etc

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 16: Introduction to php

Introduction to PHP

16

PHP Operators

bull All the operators such as arithmetic

assignment Comparison and logical operators

are similar to the operators in C and C++

bull In PHP the string concatenation operator is

denoted by lsquorsquo ndash For eg

bull $name = ldquoMy name isrdquo$myname

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 17: Introduction to php

Introduction to PHP

17

PHP Statements bull IF statement

if (ltconditiongt)

php code goes here

else

php code goes here

bull Alternative Syntax

if(ltconditiongt) html code goes here

else html code goes here

endif

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 18: Introduction to php

Introduction to PHP

18

PHP Statements (cont) bull For loop

for($i=0$i lt 10$++i)

echo(ldquothe value is rdquo $i)

ndash Alternative Syntax

for($i=0$i lt 10$++i)

html code goes here

endfor

bull While loop

bull Do-While loop

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 19: Introduction to php

Introduction to PHP

19

Functions

bull Function declaration in PHP

function my_func(ltparametersgt)

do something in the function

ndash for eg

function sayHello()

echo(ldquoltBgthello amrishltBgtltBRgtrdquo)

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 20: Introduction to php

Introduction to PHP

20

Functions (cont)

bull Assigning functions to the variables

ndash for eg

bull $hello = ldquomy_funcrdquo bull to invoke the function my_func() through the variable

$hello( )

bull When an argument is to be passed by

reference an ampersand (amp) is placed before

the parameter name

ndash for eg

my_func(amp$my_refvar)

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 21: Introduction to php

Introduction to PHP

21

Arrays

bull contains value set

bull each element has a value data stored in the

element

bull And has a key by which the element can be

referred to

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 22: Introduction to php

Introduction to PHP

22

Initializing Arrays

bull No of ways to initialize the array

ndash For eg

bull $ncststaff[] = ldquoamrishrdquo $ncststaff[] = ldquomuralirdquo $ncststaff[] = ldquonarayanrdquo bull $ncststaff[123] = ldquoamrishrdquo $ncststaff[122] = ldquomuralirdquo $ncststaff[121] = ldquonarayanrdquo bull $ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo)

ndash to change the indices of the array use =gt operator

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 23: Introduction to php

Introduction to PHP

23

Accessing the Array Elements bull The elements in the array can be accessed by

using the list and each constructs

ndash for eg

while(list($key$value) = each(countries))

echo(ldquo$valueltBRgtnrdquo)

ndash current(ltarraynamegt) gives the current value

being accessed key(ltarraynamegt) gives the index

of the current element that is being accessed

ndash prev(ltarraynamegt) gives the previous element

ndash next(ltarraynamegt) gives the next element

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 24: Introduction to php

Introduction to PHP

24

Accessing the Array Elements (cont)

ndash Array_walk(ltarraynamegtltfunction_namegt)

bull function_name is the function that is written for every

member of an array

bull For eg

$ncststaff = array (ldquoamrishrdquo ldquomuralirdquo ldquonarayanrdquo) array_walk ($ncststaff printstaff)

function to print each element of the array

function printstaff($names)

echo ldquoltBgt$namesltBgtltBRgtnrdquo

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 25: Introduction to php

Introduction to PHP

25

Arrays (cont)

bull $ncststaff = array (ldquodakerdquo =gt array(ldquoamrishrdquo ldquolakshanardquo ldquovenkatrdquo) ldquospcrdquo =gt array(ldquonarayanrdquo ldquomuralirdquoldquoprasadrdquo))

ndash creates a two dimensional array

bull Sorting Functions

ndash sort() sorts the elements in the numeric and

alphabetical order

ndash rsort() sorts the elements in the reverse order

ndash asort() sorts the elements in the array without

changing the indices

ndash ksort() sorts the arrays by key

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 26: Introduction to php

Introduction to PHP

26

Classes

bull Class is a template of an object and includes

the properties and methods that describe an

object and behavior

bull Class in PHP is defined using class statement

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 27: Introduction to php

Introduction to PHP

27

Classes (cont) bull For eg

lt

class company

define the properties

var $companyname

define the methods

function company($cname)

$this-gtcompanyname = $cname

function getnames($idcode)

return the name of the employee for the required idcode

gt

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 28: Introduction to php

Introduction to PHP

28

PHP Richness

bull PHP comes with myriad of options ie

supports several APIs and interfaces to other

programming tools such as

ndash Database connectivity

ndash LDAP

ndash XML

ndash Mail protocols such as IMAP SMTP

ndash Image functions

etchellip

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 29: Introduction to php

Introduction to PHP

29

Support for Regular Expressions

bull Not pretty things to look at and work with ndash Eg ^+++$

bull PHP takes over the headache from the programmers for explicitly coding for pattern matching

bull Functions ndash ereg() and eregi()

ndash ereg_replace() amp eregi_replace()

ndash split()

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 30: Introduction to php

Introduction to PHP

30

Image Generation amp Manipulation

bull PHP offers powerful set of functions for

generating and manipulating the images

ndash Rendering regular geometric figures modifying

images

ndash manipulate text font and color and even the pixels

in the image

bull hellipcreating the images on the fly

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 31: Introduction to php

Introduction to PHP

31

Image Generation amp Manipulation

(cont) bull PHP uses the GD library for the most of the image

functionality that it offers

bull GD library is used for generating the two-dimensional graphics

bull PHP APIrsquos provides us with functions to ndash Create delete resize and modify images

ndash Draw basic geometric figures

ndash Manipulate text and fonts

ndash Manipulate colors

ndash Interlace and manipulate pixels

ndash Handle PostScript files

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 32: Introduction to php

Introduction to PHP

32

Mailing functions

bull Sending E-Mails ndash Mail()

bull Used to send simple text messages

bull Depends on the local mail delivery system

ndash Using SMTP

bull Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails

bull Receiving E-Mails ndash PHP works out well with the IMAP protocol

ndash Rich set of support functions

bull Imap_open impa_delete imap_close imap_mail_copy imap_mail_move etc

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 33: Introduction to php

Introduction to PHP

33

PHP-Database Connectivity

bull Supports APIs for accessing large number of

databases

bull ODBC is a standard API for accessing a

database that has PHP support

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 34: Introduction to php

Introduction to PHP

34

PHP-Database Connectivity

bull Some of Oracle 8x functions

ndash OCILogon

ndash OCILogoff

ndash OCIParse

ndash OCIFetch OCIFetchInto OCIFetchStatement

ndash OCIExecute

ndash OCIFreeStatement

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 35: Introduction to php

Introduction to PHP

35

LDAP Support in PHP

bull PHP provides LDAP APIrsquos that allows the programmers to create LDAP clients by

providing transparent access to backend LDAP

directory servers

ndash For eg

bull Web based e-mail client

bull Telephone Directory

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 36: Introduction to php

Introduction to PHP

36

XML Support in PHP

bull PHP supports a set of functions that can be

used for writing PHP-based XML applications

bull These functions are used for parsing well

formed XML document

Introduction to PHP

37

THANK YOU

Page 37: Introduction to php

Introduction to PHP

37

THANK YOU