+ All Categories
Home > Documents > UNIT IV PART A

UNIT IV PART A

Date post: 28-Feb-2018
Category:
Upload: essaki-muthu
View: 213 times
Download: 0 times
Share this document with a friend

of 43

Transcript
  • 7/25/2019 UNIT IV PART A

    1/43

    PART - A

    1. What is XML parse tree? [N/D 15]

    XML documents form a tree structure that starts at "the root" and branches to "the

    leaves".

    XML documents are formed as element trees.

    An XML tree starts at a root elementand branches from the root to hil! elements.

    All elements can have sub elements (child elements)

    .....

    ". Wh# is X$LT an important tool in !e%elopment o& 'e( appliations? [M/) 1*]

    The original document is not changed rather! a ne document is created based on the

    content of an e#isting one.T$%icall$! in%ut documents are XML files! but an$thing from

    hich the %rocessor can build an X&uer$ and X'ath ata Modelcan be used! for

    e#am%le relational databasetables! or geogra%hical information s$stems.

    +. When sho,l! the s,per lo(al arra#s in PP (e ,se!? Whih s,per lo(al arra# in

    PP 'o,l! ontain a TML &orms P0$T !ata? [M/) 1*]

    *L+,AL- is a '' su%er global variable hich is used to access global variables from

    an$here in the '' scri%t (also from ithin functions or methods).

    '' stores all global variables in an arra$ called *L+,AL-index0. The indexholds the

    name of the variable.

    The e#am%le belo shos ho to use the su%er global variable *L+,AL-1

  • 7/25/2019 UNIT IV PART A

    2/43

    addition()

    echo 9

    2>n the e#am%le above! since 9 is a variable %resent ithin the *L+,AL- arra$! it is also

    accessible from outside the function'' ='+-T is idel$ used to collect form data after submitting an TML form ith

    method3"%ost". ='+-T is also idel$ used to %ass variables.=-?@?8?&-T=MT+80 B ?eturns the reCuest method used to access the

    %age (such as '+-T)

    . Name an# &o,r (,ilt-in &,ntions in PP. [N/D 15]

    arra$()B Dreates an arra$

    cal=da$s=in=month() B ?eturns the number of da$s in a month for a s%ecified $ear and

    calendar

    date.time9one B The default time9one (used b$ all date/time functions)

    chdir()B Dhanges the current director$

    5. De&ine XML.

    23tensi(le Mar4,p Lan,ae(XML) is a marEu% language that defines a set of rules

    for encoding documents in a format that is both humanBreadable and machineBreadable. t

    is defined b$ the FGD8s XML H.I -%ecification and b$ several other related

    s%ecifications! all of hich are free o%en standards.The basic building blocE of an XML document is an element! defined b$ tags. An

    element has a beginning and an ending tag. All elements in an XML document are

    contained in an outermost element Enon as the root element.*. De&ine DTD.

    A !o,ment t#pe !e&inition(DTD) is a set of marEu% declarations that !e&inea

    document t$%e for an -*MLBfamil$ marEu% language (-*ML! XML! and TML). A

    Do,ment T#pe De&inition(DTD) !e&inesthe legal building blocEs of an XML

    document. t !e&inesthe document structure ith a list of legal elements and attributes.

    . What are the XML r,les &or !istin,ishin (et'een the ontent o& a !o,ment an!

    the XML mar4,p element?

    The start of XML marEu% elements is identified b$ either the less than s$mbol (

  • 7/25/2019 UNIT IV PART A

    3/43

    Three other characters! the greater than s$mbol (>)! the a%ostro%he or single Cuote

    (K) and the double Cuotation marEs () are used b$ XML for marEu%.

    To use these s%ecial characters as content ithin $our document! $ou must use the

    corres%onding general XML entit$.

    6. What is D0M?The D0Mis a FGD (Forld Fide Feb Donsortium) standard. The D0Mdefines a

    standard for accessing documents1 "The FGD Do,ment 0(7et Mo!el(D0M) is a

    %latform and languageBneutral interface that allos %rograms and scri%ts to d$namicall$

    access and u%date the content! structure! and st$le of a document."

    8. What is X$LT?

    X$LT(23tensi(le$t#lesheet Lan,ae Trans&ormations) is a language

    for transformingXMLdocuments into other XML documents! or other formats such

    as TMLfor eb %ages!%lain te#tor into X-L ormatting +bNects! hich ma$

    subseCuentl$ be converted to other formats! such as '! 'ost-cri%tand 'O*.19. What is meta!ata?

    Meta!atais sim%l$ data about data! or! to %ut it another a$! data that describes other

    data. TaEe! for e#am%le! an XML document. An XML document contains marEu%! hich

    is a form of metadata. Donsider this fragment1

    The foobar librar$ contains the routines foo() and bar().

    The tag is metadata that tells us that the string it contains is a %aragra%h. The

    and tags are metadata that tell us that the strings the$

    contain are librar$ names and routine names res%ectivel$.

    11. What are the ,ses o& XLin4:Xpath:X;,er#?.

    XLinE is used to create h$%erlinEs in XML documents.X'ath1 %rovides a common s$nta# and semantics for functionalit$ shared beteen X-LT

    and X'ointer.

    X&uer$1 Cuer$ language. t facilitates the data e#traction from XML documents.1". De&ine PP.PP1 $%erte#t 're%rocessor is a serverBside scri%tinglanguage designed for eb

    develo%mentbut also used as a generalB%ur%ose %rogramming language. '' code ma$

    be embedded into TMLcode! or it can be used in combination ith various eb

    tem%late s$stems! eb content management s$stemsand eb frameorEs.

  • 7/25/2019 UNIT IV PART A

    4/43

    '' code is usuall$ %rocessed b$ a '' inter%reterim%lemented as a modulein the eb

    server or as a Dommon *atea$ nterface(D*) e#ecutable.1+. What are the r,les to 'rite %aria(les in PP?

    A variable can have a short name (liEe # and $) or a more descri%tive name (age!

    carname! total=volume).

    ?ules for '' variables1

    A variable starts ith the sign! folloed b$ the name of the variable

    A variable name must start ith a letter or the underscore character

    A variable name cannot start ith a number

    A variable name can onl$ contain al%haBnumeric characters and underscores (AB9!

    IBP! and = )

    @ariable names are caseBsensitive (age and A* are to different variables)

    1. What is meant (# R$$ an! AT0M?

    ?--stands for both ?ich -ite -ummar$ and ?eall$ -im%le -$ndication but it ala$s

    refers to the same technolog$. t is a mean of transmitting and u%dating nes in an

    automated a$. Most nes sites (including virtuall$ all blogs) ill %ublish hat is called

    an ?-- feed hich is regularl$ u%dated ith the latest available headlines and/or articles.

    The ?-- feed is not human readable. t is an XML format hich is designed to be read

    b$ machines rather than humans.

    The name Atom a%%lies to a %air of related Feb standards. The Atom -$ndication

    ormat is an XML language used for eb feeds! hile the Atom 'ublishing

    'rotocol (Atom'ub or A'') is a sim%le TT'Bbased %rotocol for creating and u%dating

    eb resources. A feed contains entries! hich ma$ be headlines! fullBte#t articles!

    e#cer%ts! summaries! and/or linEs to content on a ebsite! along ith various metadata.

    The Atom format as develo%ed as an alternative to ?--.

    15. o' to onnet a !ata(ase in PP?

    Fe should establish a connection to the M$-&L database. This is an e#tremel$ im%ortant

    ste% because if our scri%t cannot connect to its database! our Cueries to the database ill

    fail. A good %ractice hen using databases is to set the username! the %assord and the

    http://webreference.fr/defintions/rss-atom-xmlhttp://webreference.fr/defintions/rss-atom-xml
  • 7/25/2019 UNIT IV PART A

    5/43

    database name values at the beginning of the scri%t code. f e need to change them later!

    it ill be an eas$ tasE.

    username3"our=username"%assord3"our=%assord"database3"our=database"Fe should re%lace "our=username"! "our=%assord" and "our=database" ith the

    M$-&L username! %assord and database that ill be used b$ our scri%t.Oe#t e should connect our '' scri%t to the database. This can be done ith the

    m$sCl=connect '' function1m$sCl=connect(localhost!username!%assord)

    Part < =

    1. Write a PP proram to !o strin manip,lations. [No%/De15]>1*

    olloing are valid e#am%les of string

    string=H 3 "This is a string in double Cuotes"

    string=6 3 "This is a somehat longer! singl$ Cuoted string"

    string=GP 3 "This string has thirt$Bnine characters"

    string=I 3 "" // a string ith 9ero characters

    -ingl$ Cuoted strings are treated almost literall$! hereas doubl$ Cuoted strings re%lace variables

    ith their values as ell as s%eciall$ inter%reting certain character seCuences.

    This ill %roduce the folloing result S

    M$ variable ill not %rintQRn

    M$ name ill %rint

  • 7/25/2019 UNIT IV PART A

    6/43

    $trin @onatenation 0perator

    To concatenate to string variables together! use the dot (.) o%erator

    This ill %roduce the folloing result S

    ello Forld H6GU

    strlen> &,ntion

    The strlen() function is used to find the length of a string.

    Let8s find the length of our string "ello orldQ"1

    This ill %roduce the folloing result S

    H6

    strpos> &,ntion

    The str%os() function is used to search for a string or character ithin a string. f a match is

    found in the string! this function ill return the %osition of the first match. f no match is found!

    it ill return AL-. Let8s see if e can find the string "orld" in our string S

    This ill %roduce the folloing result S

    V

  • 7/25/2019 UNIT IV PART A

    7/43

    To ensure all the letters in a s%ecific string ere u%%ercase! e can use the strtou%%er()function

    as follos1

  • 7/25/2019 UNIT IV PART A

    8/43

    str 3 "ho long is a %iece of string2"

    cased 3 ucfirst(str)

    //is%la$s1 o long is a %iece of string2

    echo cased

    ". 23plain in !etail a(o,t i XML $hema [No% / De 15] >6

    Let8s have a looE at this XML document called "shi%order.#ml"

    Yohn-mith

    +laOordmann Langgt6G

    UIII-tavanger

    Oora$

    m%ire,urlesCue

    -%ecialdition

    H

    HI.PI

    ide$ourheart

    H

    P.PI

    The XML document above consists of a root element! "shi%order"! that contains a

    reCuired attribute called "orderid". The "shi%order" element contains three different child elements1 "order%erson"! "shi%to"

    and "item".

    The "item" element a%%ears tice! and it contains a "title"! an o%tional "note" element! a

    "Cuantit$"! and a "%rice" element.

  • 7/25/2019 UNIT IV PART A

    9/43

    The line above1 #mlns1#si3"htt%1//.G.org/6IIH/XML-chemaBinstance" tells the

    XML %arser that this document should be validated against a schema.

    The line1 #si1noOames%ace-chemaLocation3"shi%order.#sd" s%ecifies F? the

    schema resides (here it is in the same folder as "shi%order.#ml").

    @reate an XML $hema

    Oo e ant to create a schema for the XML document above.

    Fe start b$ o%ening a ne file that e ill call "shi%order.#sd".

    To create the schema e could sim%l$ follo the structure in the XML document and

    define each element as e find it.

    Fe ill start ith the standard XML declaration folloed b$ the #s1s element that definesa schema1

    ...

    n the schema above e use the standard names%ace (#s)! and the ? associated ith

    this names%ace is the -chema language definition! hich has the standard value of

    htt%1//.G.org/6IIH/XML-chema.

    Oe#t! e have to define the "shi%order" element.

    This element has an attribute and it contains other elements! therefore e consider it as a

    com%le# t$%e.

    The child elements of the "shi%order" element is surrounded b$ a #s1seCuence element

    that defines an ordered seCuence of sub elements1

    ...

  • 7/25/2019 UNIT IV PART A

    10/43

    +. List at least &i%e sini&iant !i&&erenes (et'een DTD an! XML shema &or !e&inin

    XML !o,ment str,t,res 'ith appropriate e3amples.[Ma#/),ne 1*] >6

    XML $hema %s. DTD T! or ocument T$%e efinition! and XML-chema! hich is also Enon as

    X-! are to a$s of describing the structure and content of an XML document.

    T is the older of the to! and as such! it has limitations that XML -chema has

    tried to im%rove.

    The first difference beteen T and XML -chema! is names%ace aareness

    XML -chema is! hile T is not.

    Oames%ace aareness removes the ambiguit$ that can result in having certain

    elements and attributes from multi%le XML vocabularies! b$ giving them

    names%aces that %ut the element or attribute into conte#t.

    'art of the reason h$ XML -chema is names%ace aare hile T is not! is

    the factthat XML -chema is ritten in XML! and T is not.

    Therefore! XML -chemas can be %rogrammaticall$ %rocessed Nust liEe an$ XML

    document.

    XML -chema also eliminates the needto learn another language! as it is ritten in

    XML! unliEe T.

    Another Ee$ advantage of XML -chema! is its abilit$ to im%lement strong t$%ing.

    An XML -chema can define the datat$%e of certain elements! and even constrain

    it to ithin s%ecific lengths or values.

    This abilit$ ensures that the data stored in the XML document is accurate.

    T lacEs strong t$%ing ca%abilities! and has no a$ of validating the content to

    data t$%es.

    XML -chema has a ealth of derived and builtBin data t$%es to validate content.

  • 7/25/2019 UNIT IV PART A

    11/43

    t also has uniform data t$%es! but as all %rocessors and validators need to su%%ort

    these data t$%es! it often causes older XML %arsers to fail.

    A characteristic of T that %eo%le often consider both as an advantage and

    disadvantage! is the abilit$ to define Ts inline! hich XML -chema lacEs.

    This is goodhen orEing ith small files! as it allos $ou to contain both the

    content and the schema ithin the same document! but hen it comes to larger

    documents! e have to %ull content ever$ time hile e retrieve the schema. This

    can lead to serious overhead that can degrade %erformance.

    H. XML -chema is names%ace aare! hile T is not.

    6. XML -chemas are ritten in XML! hile Ts are not.

    G. XML -chema is strongl$ t$%ed! hile T is not.

    U. XML -chema has a ealth of derived and builtBin data t$%es that are not available in

    T.

    5. XML -chema does not allo inline definitions! hile T does.

    No. DTD X$D

    H) T stands for Do,ment T#pe

    De&inition.

    X- stands for XML -chema efinition.

    6) Ts are derived from $MLs$nta#. X-s are ritten in XML.

    G) T !oesnBt s,pport !atat#pes. X- s,pports !atat#pesfor elements and attributes.

    U) T !oesnBt s,pport namespae. X- s,pports namespae.

    5) T !oesnBt !e&ine or!erfor child

    elements.

    X- !e&ines or!erfor child elements.

    V) T is not e3tensi(le. X- is e3tensi(le.

    4) T is not simple to learn.. X- is simple to learnbecause $ou don8t need to lear

  • 7/25/2019 UNIT IV PART A

    12/43

    ne language..

    ) T %rovides less ontrolon XML

    structure.

    X- %rovides more ontrolon XML structure

    . 23plain in !etail a(o,t XML parsers an! Cali!ation [N / D 15] >6

    XML PAR$2R$

    An XML %arser is a softare librar$ or %acEage that %rovides interfaces for client a%%lications to

    orE ith an XML document. The XML 'arser is designed to read the XML and create a a$

    for %rograms to use XML.

    XML %arser validates the document and checE that the document is ell formatted.Let8s understand the orEing of XML %arser b$ the figure given belo1

    T$%es of XML 'arsers

    These are the to main t$%es of XML 'arsers1

    H. +M

    6. -AX

    D0M >Do,ment 0(7et Mo!el

    A +M document is an obNect hich contains all the information of an XML document. t iscom%osed liEe a tree structure. The +M 'arser im%lements a +M A'. This A' is ver$

    sim%le to use.

  • 7/25/2019 UNIT IV PART A

    13/43

    Eeat,res o& D0M Parser

    A +M 'arser creates an internal structure in memor$ hich is a +M document obNect and the

    client a%%lications get information of the original XML document b$ invoEing methods on this

    document obNect.

    +M 'arser has a tree based structure.

    A!%antaes

    H) t su%%orts both read and rite o%erations and the A' is ver$ sim%le to use.

    6) t is %referred hen random access to idel$ se%arated %arts of a document is reCuired.

    Disa!%antaes

    H) t is memor$ inefficient. (Donsumes more memor$ because the hole XML document needs

    to loaded into memor$).

    6) t is com%arativel$ sloer than other %arsers.

    $AX >$imple APF &or XML

    A -AX 'arser im%lements -AX A'. This A' is an event based A' and less intuitive.

    Eeat,res o& $AX Parser

    t does not create an$ internal structure.

    Dlients does not Eno hat methods to call! the$ Nust overrides the methods of the A'

    and %lace his on code inside method.

    t is an event based %arser! it orEs liEe an event handler in Yava.

    A!%antaes

    H) t is sim%le and memor$ efficient.

    6) t is ver$ fast and orEs for huge documents.

    Disa!%antaes

    H) t is eventBbased so its A' is less intuitive.

    6) Dlients never Eno the full information because the data is broEen into %ieces.

    XML CALFDATF0N

    A ell formed XML document can be validated against T or -chema.

    A ellBformed XML document is an XML document ith correct s$nta#. t is ver$ necessar$ to

    Eno about valid XML document before Enoing XML validation.

    Cali! XML !o,ment

    t must be ell formed (satisf$ all the basic s$nta# condition)

  • 7/25/2019 UNIT IV PART A

    14/43

    t should be behave according to %redefined T or XML schema

    R,les &or 'ell &orme! XML

    o t must begin ith the XML declaration.

    o t must have one uniCue root element.

    o All start tags of XML documents must match end tags.

    o XML tags are case sensitive.

    o All elements must be closed.

    o All elements must be %ro%erl$ nested.

    o All attributes values must be Cuoted.

    o XML entities must be used for s%ecial characters.

    5. List the essential &eat,res o& XML parsers. Ma$/Yune HV0 ()

    XML is idel$ used in the era of eb develo%ment. t is also used to sim%lif$ data storage and

    data sharing.

    The main features or advantages of XML are given belo.

    1 XML separates !ata &rom TML

    f e need to dis%la$ d$namic data in $our TML document! it ill taEe a lot of orE to

    edit the TML each time the data changes.

    Fith XML! data can be stored in se%arate XML files. This a$ e can focus on using

    TML/D-- for dis%la$ and la$out! and be sure that changes in the underl$ing data ill

    not reCuire an$ changes to the TML.

    Fith a fe lines of Yava-cri%t code! e can read an e#ternal XML file and u%date the

    data content of $our eb %age.

    " XML simpli&ies !ata sharin

    n the real orld! com%uter s$stems and databases contain data in incom%atible formats.

    XML data is stored in %lain te#t format. This %rovides a softareB and hardareB

    inde%endent a$ of storing data.

    This maEes it much easier to create data that can be shared b$ different a%%lications.

    + XML simpli&ies !ata transport

    +ne of the most timeBconsuming challenges for develo%ers is to e#change data beteen

    incom%atible s$stems over the nternet.

  • 7/25/2019 UNIT IV PART A

    15/43

    #changing data as XML greatl$ reduces this com%le#it$! since the data can be read b$

    different incom%atible a%%lications.

    XML simpli&ies Plat&orm hane

    %grading to ne s$stems (hardare or softare %latforms)! is ala$s time consuming.

    Large amounts of data must be converted and incom%atible data is often lost.

    XML data is stored in te#t format. This maEes it easier to e#%and or u%grade to ne

    o%erating s$stems! ne a%%lications! or ne brosers! ithout losing data.

    5 XML inreases !ata a%aila(ilit#

    ifferent a%%lications can access $our data! not onl$ in TML %ages! but also from XML

    data sources.

    Fith XML! $our data can be available to all Einds of "reading machines" (andheld

    com%uters! voice machines! nes feeds! etc)! and maEe it more available for blind %eo%le!

    or %eo%le ith other disabilities.

    * XML an (e ,se! to reate ne' internet lan,aes

    A lot of ne nternet languages are created ith XML.

    ere are some e#am%les1

    o XTML

    o F-L for describing available eb services

    o FA' and FML as marEu% languages for handheld devices

    o ?-- languages for nes feeds

    o ? and +FL for describing resources and ontolog$

    o -ML for describing multimedia for the eb

    *. Write notes on X$L an! X$L Trans&ormation. >1*

    What is X$L?

    X-L is a language for e#%ressing st$le sheets. An X-L st$le sheet is! liEe ith D--! a file

    that describes ho to dis%la$ an XML document of a given t$%e.

    X-L shares the functionalit$ and is com%atible ith D--6 (although it uses a different

    s$nta#).

    https://www.w3.org/Style/CSShttps://www.w3.org/Style/CSS
  • 7/25/2019 UNIT IV PART A

    16/43

    A transformation language for XML documents1 X$LT. +riginall$ intended to %erform

    com%le# st$ling o%erations! liEe the generation of tables of contents and inde#es! it is

    no used as a general %ur%ose XML %rocessing language.

    X-LT is thus idel$ used for %ur%oses other than X-L! liEe generating TML eb

    %ages from XML data.

    Advanced st$ling features! e#%ressed b$ an XML document t$%e hich defines a set of

    elements called Eormattin 0(7ets! and attributes (in %art borroed from D--6

    %ro%erties and adding more com%le# ones.

    o' Does Ft Wor4?

    -t$ling reCuires a source XML documents! containing the information that the st$le sheet ill

    dis%la$ and the st$le sheet itself hich describes ho to dis%la$ a document of a given t$%e.

    The folloing shos a sam%le XML file and ho it can be transformed and rendered.

    The XML &ile

    *eneral ?oad ,uilding noises.

    Dome off it Mr ent! $ou can8t in

    $ou Eno. There8s no %oint in l$ing

    don in the %ath of %rogress.

    8ve gone off the idea of %rogress.

    t8s overrated

    This XML file doesn8t contain an$ %resentation information! hich is contained in the

    st$lesheet.

    -e%arating the document8s content and the document8s st$ling information allos

    dis%la$ing the same document on different media (liEe screen! %a%er! cell %hone)! and it

  • 7/25/2019 UNIT IV PART A

    17/43

  • 7/25/2019 UNIT IV PART A

    18/43

  • 7/25/2019 UNIT IV PART A

    19/43

    Astylesheetroot tag! including versionand namespaceattributes (as seen in the e#am%le

    above)1

    version3"H.I"

    #mlns1#sl3"htt%1//.G.org/HPPP/X-L/Transform"

    Assoiation o& XML an! an X$LT &ile

    X-LT as alread$ im%lemented in 5.5.! i.e. in the last millenium...

    ....

    There e#ist various soBcalled X-LT %rocessors. Most %rogramming languages and all ellBEno

    serverBside scri%ting languages liEe '' include an X-LT librar$. XML editors usuall$ include

    an X-LT %rocessor.

    ,elo is the com%lete code for a sim%le "ello X-LT" e#am%le.

    XML &ile >so,re

    hello.#ml

    ello

    ere is some content

    Fritten b$ W-.

    Fanted result document

  • 7/25/2019 UNIT IV PART A

    20/43

    ello

    ello

    ere is some content

    Fritten b$ W-

    The X$LT $t#lesheet

    hello.#slt

  • 7/25/2019 UNIT IV PART A

    21/43

    . 23plain in !etails a(o,t %aria(les in PP.

    The main a$ to store information in the middle of a '' %rogram is b$ using a variable.

    ere are the most im%ortant things to Eno about variables in ''.

    All variables in '' are denoted ith a leading dollar sign ().

    The value of a variable is the value of its most recent assignment.

    @ariables are assigned ith the 3 o%erator! ith the variable on the leftBhand side and the

    e#%ression to be evaluated on the right.

    @ariables can! but do not need! to be declared before assignment.

    @ariables in '' do not have intrinsic t$%es B a variable does not Eno in advancehether it ill be used to store a number or a string of characters.

    @ariables used before the$ are assigned have default values.

    '' does a good Nob of automaticall$ converting t$%es from one to another hen

    necessar$.

  • 7/25/2019 UNIT IV PART A

    22/43

    '' variables are 'erlBliEe.

    '' has a total of eight data t$%es hich e use to construct our variables S

    FnteersS are hole numbers! ithout a decimal %oint! liEe UHP5.

    Do,(lesS are floatingB%oint numbers! liEe G.HUH5P or UP.H.

    =ooleansS have onl$ to %ossible values either true or false.

    NHLLS is a s%ecial t$%e that onl$ has one value1 OLL.

    $trinsS are seCuences of characters! liEe 8'' su%%orts string o%erations.8

    Arra#sS are named and inde#ed collections of other values.

    0(7etsS are instances of %rogrammerBdefined classes! hich can %acEage u% both other

    Einds of values and functions that are s%ecific to the class.

    Reso,resS are s%ecial variables that hold references to resources e#ternal to '' (such

    as database connections).

    The first five aresimple types! and the ne#t to (arra$s and obNects) are com%ound B the

    com%ound t$%es can %acEage u% other arbitrar$ values of arbitrar$ t$%e! hereas the sim%le

    t$%es cannot.

    Fnteers

    The$ are hole numbers! ithout a decimal %oint! liEe UHP5. The$ are the sim%lest t$%e .the$

    corres%ond to sim%le hole numbers! both %ositive and negative. ntegers can be assigned to

    variables! or the$ can be used in e#%ressions! liEe so S

    int=var 3 H6GU5

    another=int 3 BH6GU5 : H6GU5

    nteger can be in decimal (base HI)! octal (base )! and he#adecimal (base HV) format. ecimal

    format is the default! octal integers are s%ecified ith a leading I! and he#adecimals have a

    leading I#.

    or most common %latforms! the largest integer is (6]]GH . H) (or 6!HU4!UG!VU4)! and the

    smallest (most negative) integer is . (6]]GH . H) (or .6!HU4!UG!VU4).

    Do,(les

    The$ liEe G.HUH5P or UP.H. ,$ default! doubles %rint ith the minimum number of decimal

    %laces needed. or e#am%le! the code S

  • 7/25/2019 UNIT IV PART A

    23/43

    man$ 3 6.6II

    man$=6 3 6.6HHH6II

    fe 3 man$ : man$=6

    %rint("man$ : man$=6 3 fe
    ")

    2>

    t %roduces the folloing broser out%ut S

    6.6 : 6.6HHH6 3 U.5

    =oolean

    The$ have onl$ to %ossible values either true or false. '' %rovides a cou%le of constants

    es%eciall$ for use as ,ooleans1 T? and AL-! hich can be used liEe so S

    if (T?)

    %rint("This ill ala$s %rint
    ")

    else

    %rint("This ill never %rint
    ")

    Fnterpretin other t#pes as =ooleans

    ere are the rules for determine the "truth" of an$ value not alread$ of the ,oolean t$%e S

    f the value is a number! it is false if e#actl$ eCual to 9ero and true otherise.

    f the value is a string! it is false if the string is em%t$ (has 9ero characters) or is the

    string "I"! and is true otherise.

    @alues of t$%e OLL are ala$s false.

    f the value is an arra$! it is false if it contains no other values! and it is true otherise.

    or an obNect! containing a value means having a member variable that has been

    assigned a value.

    @alid resources are true (although some functions that return resources hen the$ aresuccessful ill return AL- hen unsuccessful).

    on8t use double as ,ooleans.

    ach of the folloing variables has the truth value embedded in its name hen it is used in a

    ,oolean conte#t.

  • 7/25/2019 UNIT IV PART A

    24/43

    true=num 3 G : I.HUH5P

    true=str 3 "Tried and true"

    true=arra$UP0 3 "An arra$ element"

    false=arra$ 3 arra$()

    false=null 3 OLL

    false=num 3 PPP B PPP

    false=str 3 ""

    NHLL

    OLL is a s%ecial t$%e that onl$ has one value1 OLL. To give a variable the OLL value!

    sim%l$ assign it liEe this S

    m$=var 3 OLL

    The s%ecial constant OLL is ca%itali9ed b$ convention! but actuall$ it is case insensitive $ou

    could Nust as ell have t$%ed S

    m$=var 3 null

    A variable that has been assigned OLL has the folloing %ro%erties S

    t evaluates to AL- in a ,oolean conte#t.

    t returns AL- hen tested ith s-et() function.

    $trins

    The$ are seCuences of characters! liEe "'' su%%orts string o%erations". olloing are valid

    e#am%les of string

    string=H 3 "This is a string in double Cuotes"

    string=6 3 "This is a somehat longer! singl$ Cuoted string"

    string=GP 3 "This string has thirt$Bnine characters"

    string=I 3 "" // a string ith 9ero characters

    -ingl$ Cuoted strings are treated almost literall$! hereas doubl$ Cuoted strings re%lace

    variables ith their values as ell as s%eciall$ inter%reting certain character seCuences.

  • 7/25/2019 UNIT IV PART A

    25/43

    literall$ 3 8M$ variable ill not %rintQ8

    %rint(literall$)

    %rint "
    "

    literall$ 3 "M$ variable ill %rintQ"

    %rint(literall$)

    2>

    This ill %roduce folloing result S

    M$ variable ill not %rintQRn

    M$ name ill %rint

    There are no artificial limits on string length B ithin the bounds of available memor$! $ou

    ought to be able to maEe arbitraril$ long strings.

    -trings that are delimited b$ double Cuotes (as in "this") are %re%rocessed in both the folloing

    to a$s b$ '' S

    Dertain character seCuences beginning ith bacEslash (R) are re%laced ith s%ecial

    characters

    @ariable names (starting ith ) are re%laced ith string re%resentations of their values.

    The esca%eBseCuence re%lacements are S

    Rn is re%laced b$ the neline character

    Rr is re%laced b$ the carriageBreturn character

    Rt is re%laced b$ the tab character

    R is re%laced b$ the dollar sign itself ()

    R" is re%laced b$ a single doubleBCuote (")

    RR is re%laced b$ a single bacEslash (R)

    6. 23plain in !etail a(o,t (,ilt < in &,ntions in PP.

  • 7/25/2019 UNIT IV PART A

    26/43

    unctions are reusable bits of code that $ou use throughout a %roNect.

    The$ hel% to better organi9e $our a%%lication as ell as eliminate the need to co%$/%aste

    re%etitive %ieces of code.

    n an ideal orld an a%%lication should not have multi%le functions doing the same thing.

    '' has a lot of built in functions and hile e are not e#%ected to learn all of them at

    once there are some useful functions that can hel% in ever$da$ %rogramming and e ill

    start from there.

    $TRFN MANFPHLATF0N EHN@TF0N$

    -ome of the most useful '' functions are string mani%ulation functions. As the name suggests

    the$ mani%ulate strings.

    EFNDFN T2 L2NT 0E A $TRFN

    The strlen() functions orEs b$ %assing a strinor %aria(leand then returns the total number of

    characters including s%aces.

    R2THRN PART 0E A $TRFN

    The substr() function is used to return a substring or %art of a string. This function has G

    %arameters hich $ou can %ass along.

    $#nta3

    substr(string! start!length)

    string a string of te#t or a variable containing a string of te#t. n%ut must be at least

    one character.

  • 7/25/2019 UNIT IV PART A

    27/43

    start thinE of the string as an arra$ starting from I0. f e anted to start from the

    first character $ou ould enter I. A negative value ill go to the end of the string.

    length (+%tional) is the number of characters returned after the start character. f this

    value is less than or eCual to the start value then it ill return false.

    @0NC2RTFN $TRFN$ T0 HPP2R 0R L0W2R @A$2

    To useful string functions that are sim%le to use are strtou%%er() andstrtoloer()! these

    functions can convert $our strings to all ''?DA- or all loercase.

    The$ are ver$ useful for case sensitive o%erations here $ou ma$ reCuire all characters to be

    loercase for e#am%le.

    $earhin &or a nee!le in a ha#sta4I

    -ometimes e need to find a substring ithin a string and to do that e can use str%os.

    $#nta3

    str%os (ha$stacE!needle!offset)

    ha$stacE this is the string in hich $ou are going to find the needlestarting from I0.

    needle this is hat $ou are going to search for in the ha$stacE.

  • 7/25/2019 UNIT IV PART A

    28/43

    offset (+%tional) search ill start from this number of characters counted from the

    beginning of the string. Dannot be negative.

    Ootice that the last e#am%le is false. That is because this function is case sensitive and could not

    find a match.

    Fe can almost maEe use of an if statement and some variables to maEe the stro%s function more

    useful and meaningful.

    This ould echo Sorry we could not find JavaScript in I am learning how to use PHP string

    functions!.

    ARFTM2TF@ MANFPHLATF0N EHN@TF0N$

    As ell as string mani%ulation function! '' also has functions to mani%ulate numbers.

  • 7/25/2019 UNIT IV PART A

    29/43

    R0HNDFN NHM=2R$

    +ne of the most commonl$ used math function is round(). This function rounds numbers ith

    decimal %oints u% or don. Fe can round a number to an integer (hole number) or to a floating

    %oint (decimal numbers).

    $#nta3

    round(val! %recision! mode)

    val is the value to be rounded.

    %recision (o%tional) number of decimal %laces to round to.

    mode the t$%e of rounding that occurs and can be one of the folloing for more

    details and e#am%les of modes see '' docs.

    +ther math functions for rounding are ceil() and floor() . To round a number to the nearest hole

    number! these functions are better suited to that %ur%ose.

    ceil() rounds fractions u%.

    floor() rounds fractions don.

  • 7/25/2019 UNIT IV PART A

    30/43

    2>

    ,oth functions reCuire a %al,eand unliEe round()! do not have an$ additional %arameters.

    2N2RATFN RAND0M NHM=2R$

    Another ver$ common math function is rand() hich returns a random number beteen to

    numbers.

    $#nta3

    rand(min! ma#)

    min (o%tional) sets the loest value to be returned. efault is I

    ma# (o%tional) sets the ma#imum value to be returned. efault returnsgetrandma#().

    Fe ill need to s%ecif$ a ma# value in order to return a larger number.

    ARRAJ EHN@TF0N$

    Arra$ or arra$() is itself a function that stores multi%le values in to a single variable. Aside from

    the arra$() function there are a number of other functions to mani%ulate arra$s! here e ill looE

    at some of the most common ones.

    ADDFN N2W 2L2M2NT$

    Adding ne elements to the end of an arra$ can be achieved b$ calling thearra$=%ush() function.

    $#nta3

    arra$=%ush(arra$! valueH! value6)

    arra$ the arra$ in hich $ou are adding ne elements to.

    valueH (reCuired) is the first value to %ush onto the end of the arra$.

  • 7/25/2019 UNIT IV PART A

    31/43

    value6 (o%tional) is the second value to %ush onto the end of the arra$.

    [ou can %ush as man$ values as $ou need.

    oever is is better to list each element in a single call liEe this1

    ,oth methods result in the same outcome. f $ou echo or %rint arra$=%ush() it ill return the

    number of items to be %ushed in to the arra$.

    f $ou var=dum%() the target arra$ $ou $ou ill see something liEe this.

    arra$(U) 7

    I0 3> string() "arcr$ U"

  • 7/25/2019 UNIT IV PART A

    32/43

  • 7/25/2019 UNIT IV PART A

    33/43

    f $ou need to sort and reverse the order of an$ arra$ then $ou can use a function called rsort(). t

    orEs e#actl$ the same a$ as sort() e#ce%t the out%ut is reversed.

    8. 23plain in !etail a(o,t @oo4ies.

    DooEies are te#t files stored on the client com%uter and the$ are Ee%t of use tracEing %ur%ose.

    '' trans%arentl$ su%%orts TT' cooEies.

    There are three ste%s involved in identif$ing returning users S

    -erver scri%t sends a set of cooEies to the broser. or e#am%le name! age! or

    identification number etc.

    ,roser stores this information on local machine for future use.

    Fhen ne#t time broser sends an$ reCuest to eb server then it sends those cooEies

    information to the server and server uses that information to identif$ the user.

    DooEies are usuall$ set in an TT' header (although Yava-cri%t can also set a cooEie directl$

    on a broser). A '' scri%t that sets a cooEie might send headers that looE something liEe this

    TT'/H.H 6II +W

    ate1 ri! IU eb 6III 6H1IG1G *MT

    -erver1 A%ache/H.G.P (OX) ''/U.IbG

    -etBDooEie1 name3#$9 e#%ires3rida$! IUBebBI4 661IG1G *MT

    %ath3/ domain3tutorials%oint.com

    Donnection1 close

    DontentBT$%e1 te#t/html

    The -etBDooEie header contains a name value %air! a *MT date! a %ath and a domain.

    The name and value ill be ?L encoded.

  • 7/25/2019 UNIT IV PART A

    34/43

    The e#%ires field is an instruction to the broser to "forget" the cooEie after the given

    time and date.

    f the broser is configured to store cooEies! it ill then Eee% this information until the

    e#%ir$ date.

    f the user %oints the broser at an$ %age that matches the %ath and domain of the

    cooEie! it ill resend the cooEie to the server.

    The broser8s headers might looE something liEe this S

    *T / TT'/H.I

    Donnection1 Wee%BAlive

    serBAgent1 Mo9illa/U.V (XHH Linu# 6.6.VBH5a%mac %%c)

    ost1 9inE.demon.co.uE1HH6V

    Acce%t1 image/gif! ]/]Acce%tBncoding1 g9i%

    Acce%tBLanguage1 en

    Acce%tBDharset1 isoB5PBH!]!utfB

    DooEie1 name3#$9

    A '' scri%t ill then have access to the cooEie in the environmental variables =D++W or

    TT'=D++W=@A?-0 hich holds all cooEie names and values. Above cooEie can be

    accessed using TT'=D++W=@A?-"name"0.

    $2TTFN @00KF2$ WFT PP

    '' %rovided setoo4ie>function to set a cooEie. This function reCuires u%to si# arguments

    and should be called before tag. or each cooEie this function has to be called

    se%aratel$.

    setcooEie(name! value! e#%ire! %ath! domain! securit$)

    ere is the detail of all the arguments S

    NameS This sets the name of the cooEie and is stored in an environment variable called

    TT'=D++W=@A?-. This variable is used hile accessing cooEies.

    Cal,eS This sets the value of the named variable and is the content that $ou actuall$

    ant to store.

    23pir#S This s%ecif$ a future time in seconds since II1II1II *MT on Hst Yan HP4I.

    After this time cooEie ill become inaccessible. f this %arameter is not set then cooEie

    ill automaticall$ e#%ire hen the Feb ,roser is closed.

  • 7/25/2019 UNIT IV PART A

    35/43

    PathS This s%ecifies the directories for hich the cooEie is valid. A single forard slash

    character %ermits the cooEie to be valid for all directories.

    DomainS This can be used to s%ecif$ the domain name in ver$ large domains and must

    contain at least to %eriods to be valid. All cooEies are onl$ valid for the host and

    domain hich created them.

    $e,rit#S This can be set to H to s%ecif$ that the cooEie should onl$ be sent b$ secure

    transmission using TT'- otherise set to I hich mean cooEie can be sent b$ regular

    TT'.

    olloing e#am%le ill create to cooEies nameand aethese cooEies ill be e#%ired after

    one hour.

    -etting DooEies ith ''

    A@@2$$FN @00KF2$ WFT PP

    '' %rovides man$ a$s to access cooEies. -im%lest a$ is to use either =D++W or

    TT'=D++W=@A?- variables. olloing e#am%le ill access all the cooEies set in above

    e#am%le.

    Accessing DooEies ith ''

  • 7/25/2019 UNIT IV PART A

    36/43

    echo TT'=D++W=@A?-"name"0. "
    "

    echo =D++W"age"0 . "
    "

    /] is eCuivalent to ]/

    echo TT'=D++W=@A?-"name"0 . "
    " 2>

    Fe can use isset>function to checE if a cooEie is set or not.

    Accessing DooEies ith ''

    D2L2TFN @00KF2 WFT PP

    +fficiall$! to delete a cooEie $ou should call setcooEie() ith the name argument onl$ but this

    does not ala$s orE ell! hoever! and should not be relied on.

    t is safest to set the cooEie ith a date that has alread$ e#%ired S

    eleting DooEies ith ''

  • 7/25/2019 UNIT IV PART A

    37/43

    19. 23plain in !etail a(o,t Re,lar 23pressions

    ?egular e#%ressions are nothing more than a seCuence or %attern of characters itself. The$

    %rovide the foundation for %atternBmatching functionalit$.

    sing regular e#%ression $ou can search a %articular string inside a another string! e can

    re%lace one string b$ another string and $ou can s%lit a string into man$ chunEs.

    '' offers functions s%ecific to to sets of regular e#%ression functions! each corres%onding to

    a certain t$%e of regular e#%ression. Fe can use an$ of them based on $our comfort.

    '+-X ?egular #%ressions

    '?L -t$le ?egular #%ressions

    P0$FX Re,lar 23pressions

    The structure of a '+-X regular e#%ression is not dissimilar to that of a t$%ical

    arithmetic e#%ression1 various elements (o%erators) are combined to form more com%le#

    e#%ressions.

    The sim%lest regular e#%ression is one that matches a single character! such as g! inside

    strings such as g! haggle! or bag.

    =ra4ets

    ,racEets (0) have a s%ecial meaning hen used in the conte#t of regular e#%ressions. The$ are

    used to find a range of characters.

    $r.No 23pression Desription

    H[9-8]

    t matches an$ decimal digit from I through P.

    6[a-]

    t matches an$ character from loerBcase a through loercase 9.

    G[A-]

  • 7/25/2019 UNIT IV PART A

    38/43

    t matches an$ character from u%%ercase A through u%%ercase _.

    U[a-]

    t matches an$ character from loercase a through u%%ercase _.

    The ranges shon above are general $ou could also use the range IBG0 to match an$ decimal

    digit ranging from I through G! or the range bBv0 to match an$ loercase character ranging

    from b through v.

    O,anti&iers

    The freCuenc$ or %osition of bracEeted character seCuences and single characters can be

    denoted b$ a s%ecial character. ach s%ecial character having a s%ecific connotation. The :! ]! 2!

    7int. range;! and flags all follo a character seCuence.

    $r.No 23pression Desription

    Hp

    t matches an$ string containing at least one %.

    6pQ

    t matches an$ string containing 9ero or more %8s.

    G p?

    t matches an$ string containing 9ero or more %8s. This is Nust an alternative a$ to use

    %].

    UpNS

    t matches an$ string containing a seCuence of N%8s

    5p":+S

    t matches an$ string containing a seCuence of to or three %8s.

    Vp": S

    t matches an$ string containing a seCuence of at least to %8s.

    4p

  • 7/25/2019 UNIT IV PART A

    39/43

    t matches an$ string ith % at the end of it.

    Up

    t matches an$ string ith % at the beginning of it.

    #am%les

    olloing e#am%les ill clear our conce%ts about matching characters.

    $r.No 23pression Desription

    H[Ua-A-]

    t matches an$ string not containing an$ of the characters ranging from a through 9 and A

    through _.

    6p.p

    t matches an$ string containing %! folloed b$ an$ character! in turn folloed b$ another %.

    GU."S

    t matches an$ string containing e#actl$ to characters.

    UV(>.QV/(

    t matches an$ string enclosed ithin and .

    5p>hpQ

    t matches an$ string containing a % folloed b$ 9ero or more instances of the seCuence %h%.

    Pre!e&ine! @harater Ranes

    or our %rogramming convenience several %redefined character ranges! also Enon as character

    classes! are available. Dharacter classes s%ecif$ an entire range of characters! for e#am%le! the

    al%habet or an integer set S

    $r.No 23pression Desription

    H[[alpha]]

  • 7/25/2019 UNIT IV PART A

    40/43

    t matches an$ string containing al%habetic characters aA through 9_.

    6[[!iit]]

    t matches an$ string containing numerical digits I through P.

    G[[aln,m]]

    t matches an$ string containing al%hanumeric characters aA through 9_ and I through P.

    U[[spae]]

    t matches an$ string containing a s%ace.

    PPBs Ree3p P0$FX E,ntions

    '' currentl$ offers seven functions for searching strings using '+-XBst$le regulare#%ressions S

    $r.No E,ntion Desription

    H ere>

    The ereg() function searches a string s%ecified b$ string for a string s%ecified b$ %attern!

    returning true if the %attern is found! and false otherise.

    6 erereplae>

    The ereg=re%lace() function searches for string s%ecified b$ %attern and re%laces %attern ith

    re%lacement if found.

    G erei>

    The eregi() function searches throughout a string s%ecified b$ %attern for a string s%ecified b$

    string. The search is not case sensitive.

    U ereireplae>

    The eregi=re%lace() function o%erates e#actl$ liEe ereg=re%lace()! e#ce%t that the search for

    %attern in string is not case sensitive.

    5 split>

    The s%lit() function ill divide a string into various elements! the boundaries of each element

    based on the occurrence of %attern in string.

    http://www.tutorialspoint.com/php/php_ereg.htmhttp://www.tutorialspoint.com/php/php_ereg_replace.htmhttp://www.tutorialspoint.com/php/php_eregi.htmhttp://www.tutorialspoint.com/php/php_eregi_replace.htmhttp://www.tutorialspoint.com/php/php_split.htmhttp://www.tutorialspoint.com/php/php_ereg.htmhttp://www.tutorialspoint.com/php/php_ereg_replace.htmhttp://www.tutorialspoint.com/php/php_eregi.htmhttp://www.tutorialspoint.com/php/php_eregi_replace.htmhttp://www.tutorialspoint.com/php/php_split.htm
  • 7/25/2019 UNIT IV PART A

    41/43

    V spliti>

    The s%liti() function o%erates e#actl$ in the same manner as its sibling s%lit()! e#ce%t that it is

    not case sensitive.

    4 s;lrease>

    The sCl=regcase() function can be thought of as a utilit$ function! converting each character

    in the in%ut %arameter string into a bracEeted e#%ression containing to characters.

    P2RL $t#le Re,lar 23pressions

    'erlBst$le regular e#%ressions are similar to their '+-X counter%arts.

    The '+-X s$nta# can be used almost interchangeabl$ ith the 'erlBst$le regular

    e#%ression functions.

    Lets give e#%lanation for fe conce%ts being used in '?L regular e#%ressionsMeta haraters

    A meta character is sim%l$ an al%habetical character %receded b$ a bacEslash that acts to give

    the combination a s%ecial meaning.

    or instance! e can search for large mone$ sums using the 8Rd8 meta character1 />[Y!]999/!

    ere Y!ill search for an$ string of numerical character.

    olloing is the list of meta characters hich can be used in '?L -t$le ?egular #%ressions.

    @harater Desription

    . a single character

    Rs a hites%ace character (s%ace! tab! neline)

    R- nonBhites%ace character

    Rd a digit (IBP)

    R a nonBdigit

    R a ord character (aB9! AB_! IBP! =)

    RF a nonBord character

    aeiou0 matches a single character in the given set

    `aeiou0 matches a single character outside the given set

    (foobarba9) matches an$ of the alternatives s%ecified

    Mo!i&iers

    -everal modifiers are available that can maEe $our orE ith rege#%s much easier! liEe case

    sensitivit$! searching in multi%le lines etc.

    http://www.tutorialspoint.com/php/php_spliti.htmhttp://www.tutorialspoint.com/php/php_sql_regcase.htmhttp://www.tutorialspoint.com/php/php_spliti.htmhttp://www.tutorialspoint.com/php/php_sql_regcase.htm
  • 7/25/2019 UNIT IV PART A

    42/43

    Mo!i&ierDesription

    i MaEes the match case insensitive

    m -%ecifies that if the string has neline or carriage

    return characters! the ` and o%erators ill no

    match against a neline boundar$! instead of a

    string boundar$

    o valuates the e#%ression onl$ once

    s Allos use of . to match a neline character

    # Allos $ou to use hite s%ace in the e#%ression for clarit$

    g *loball$ finds all matches

    cg Allos a search to continue even after a global match fails

    PPBs Ree3p P2RL @ompati(le E,ntions

    '' offers folloing functions for searching strings using 'erlBcom%atible regular e#%ressions

    S

    $r.No E,ntion Desription

    H premath>

    The %reg=match() function searches string for %attern! returning true if %attern e#ists! and

    false otherise.

    6 premathall>The %reg=match=all() function matches all occurrences of %attern in string.

    G prereplae>

    The %reg=re%lace() function o%erates Nust liEe ereg=re%lace()! e#ce%t that regular e#%ressions

    can be used in the %attern and re%lacement in%ut %arameters.

    U presplit>

    The %reg=s%lit() function o%erates e#actl$ liEe s%lit()! e#ce%t that regular e#%ressions are

    acce%ted as in%ut %arameters for %attern.

    5 prerep>

    The %reg=gre%() function searches all elements of in%ut=arra$! returning all elements

    matching the rege#% %attern.

    V pre ;,ote>

    http://www.tutorialspoint.com/php/php_preg_match.htmhttp://www.tutorialspoint.com/php/php_preg_match_all.htmhttp://www.tutorialspoint.com/php/php_preg_replace.htmhttp://www.tutorialspoint.com/php/php_preg_split.htmhttp://www.tutorialspoint.com/php/php_preg_grep.htmhttp://www.tutorialspoint.com/php/php_preg_quote.htmhttp://www.tutorialspoint.com/php/php_preg_match.htmhttp://www.tutorialspoint.com/php/php_preg_match_all.htmhttp://www.tutorialspoint.com/php/php_preg_replace.htmhttp://www.tutorialspoint.com/php/php_preg_split.htmhttp://www.tutorialspoint.com/php/php_preg_grep.htmhttp://www.tutorialspoint.com/php/php_preg_quote.htm
  • 7/25/2019 UNIT IV PART A

    43/43

    &uote regular e#%ression characters


Recommended