0% found this document useful (0 votes)
26 views49 pages

Ip 5

sdfsdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
26 views49 pages

Ip 5

sdfsdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 49
WF _ internet Programming (MU) 53 Web Extension PHP and XML * _Itis also simpler to upgrade to a new operating system, a new application, or a new browser without losing data through XML. + XML allows digital data to be accessed by a wide range of devices, including people, computers, voice machines, RSS feeds, etc. 5.1.4 How to use XML? ‘+ The use of XML by web developers is widespread. Separating data from the presentation is often done with XML. XML does not carry any information about how the data should be displayed. It does not have any information about the presentation of data. The same XML data can be used in many different presentation scenarios. Due to this, with XML there is a complete separation between data and Presentation, 5.1.5 XML Tree Structure * The structure of an XML document is self-descriptive. It forms a tree structure known as an XML tree. XML documents can be described easily using the tree structure. ‘+ Attree structure contains root elements (as a parent), child elements, and so on. Starting at the root, it Is very easy to traverse all branches and sub branches, and leaf nodes, © This XML file does not appear to have any style information associated with it. The document tree is shown below. Syntax of tree structure ...... 07> <Ram <Raheja < 09990449935 [email protected] Maharashtra “Mumbai <201007
on PHP and XML Internet Programming (MU) 5-4 Web Extension PHP an - a yermamppmtdocs/connectionder™ CD filevscyxampprntdocs) TS style information This XML file does not appear to have any sty! This Shad with it. The document tree is shown below: —~college> —Ram Raheja~/lastname> ~contnct>09990449935-[email protected] —“address> ‘“city>Maharashtra Mumbai 201007
, , , and eaddress>.
branch contains 3 sub-branches named , and . 5.1.6 Comments in XML ‘The syntax for writing comments in XMLis similar to that of HTML: ‘This is a comment > ‘Two dashes in the middle of a comment are not allowed: 5.1.7 XML Elements ‘An XML document contains XML Elements, "Trani X¥_internet Programming (MU) 55 Web Extension PHP and XML What is an XML Element? ‘AN XML element is everything from (Including) the element's start tag to (including) the element's end tag. 20,99 ‘An element ean contain text tributes other elements ora mix of the above Harry Potter J K, Rowling2005 29.99 - Learning XML <<author> Erik T, Ray</author> eb <year>2003</year> <price>39.95</price> <[book> <Jbookstore> In the example above: <tide>, <author>, <year>, and <price> have text content because they contain text (like 29.09). -<bookstore> and <book> have element contents, because they contain elements. -<book> has an attribute (category="children"). Empty XML Elements ‘An element with no content is said to be empty. In XML, you can indicate an empty element like this: <element> <Jelement> You can also use a socalled self-closing tag: <element /> 5.1.8 XML Naming Rules XML elements must follow these naming rules : ‘+ Element names are case-sensitive v Web Extension PHP and XML 6 Internet Programming (MU) 5. + Element names must start with aletter or underscore Element names cannot start with the letters xml (or XML, or Xml, etc) Element names can contain letters, digits, hyphens, underscores, and periods + Element names cannot contain spaces ‘Any name can be used, no words are reserved (except xml) Best Naming Practices <person>, <firstname>, <lastname>. Greate descriptive names like Create short and simple names, like this: <book_title> not like this: <the_ttle_of the_book>. Avoid "Ifyou name something "st-name", some software may think you want to subtract “name” fom “irs”. 18 property ofthe object “rst Avoid". Ifyou name something "firstname", some software may think th Avoid "*. Colons are reserved for namespaces (ore later), [Naming Styles ‘There are no naming styles defined for XMIL elements, But here are some commonly used: Style Example Description Lower case | <firstname> | allletters lower case Upper case | <FIRSTNAME> | Allletters upper case Underscore | «first.name> | Underscore separates words Pascal case | <FirstName> | Uppercase irs letter in each word Camet-case | <firstName> _| Uppercase first leter in each word except the first you choose a naming style, itis good to be consistent! XML documents often have a corresponding database. A ‘common practice isto use the naming rules of the database for the XML elements, 5.1.9 XMLDTD AML DTD is acronym for document type definition which is use to define the structure of XML document. The XML. document i called as Valid and Well Formed if satisfies Document type Definition, Following is the example of Document Type Definition <taml venion = "1.0" encoding = "UTF.8'> <!DOCTYPE address [ <!ELEMENT addres (name,company phone)> <IFLEMENT name (#PCDATA)> <IELEMENT company (#PCDATA)> <!ELEMENT phone (#PCDATA)> > Ve SF _tnternet Programming (MU) Web Extension PHP and XML <adderss> <eame>TanmayPatil</name> <company>NUYZ</company> <phone> 8785456055 </phone> </address> address E ELEMENT address - Defines that the note element must contain the element DOCTYPE address - Defines that the root clement of the document “name, company, phone” ! ELEMENT name - Defines the name element to be of type "ZPCDATA” ! ELEMENT company - Defines the company element to be of ype "#PCDATA™ ! ELEMENT Phone - Defines the phone element to be of type “# PCDATA” 5.110 XMLSchema Like Document Type Definition an XML Schema also describes the structure of an XML document. The XML document is called as Well-Formed document if it has correct syntax. IF An XML document is validated against an XML schema we can call it both "Well Formed” and "Valid. XML Schema XML Schema is an XML-based alternative to DTD : -<xsrcomplesType> lement name="company "type="ssstrin “<xsielement name="phone” type="xs:string’/> <</nsisequence> </xsscomplesType> -</xsiclement> “The Schema above is interpreted like this: <exscelement name="address">defines the element called address" “<xsicomplexType> the “note” element is 9 complex type “crs: seqquence> the complex type isa sequence of elements ame" type="ts: string"> the element “name” i of type string (te!) lompany" type="xs:string"> the element “company” is of type string tring"> the element “phone "is of type string WF _ Internet Programming (MU) 5-8 Web Extension PHP and XML XML Schemas are More Powerful than DTD XML Schemas ate written in NAIL XML Schemas are extensible to additions XML Schemas support data types XML Schemas support namespaces 5.1.11 XML DOM: XML Document Object Model DOM (Document Object Model) is the foundation of XML. XML documents contain nodes, which are hierarchical units of information; DOM describes those nodes and their relationships. + A DOM document is a collection of nodes or pieces of information arranged in a hierarchy. A developer can find specific information in the tree by navigating through this hierarchy. The DOM is called a tree because itis based on a hierarchy of information, * Adeveloper can add, edit, move, or remove a node within the XML DOM at any point in the process of creating an application using the API provided by XML DOM, + AILXML elements can be accessed through the XML DOM. * This code retrieves the text value of the first <firstname> element in an XML document: ‘<?xml version <college> ‘<student> ‘<firstname>Ram</frstname> ‘<lasiname> Raheja</lastname> ‘<contaet>09990449935</contact> <email> ramRtaheja@abe.com</email> <address> ‘<city>Maharashira</eity> ‘<state>Mumbai</state> <pin>201007 </pin> </address> </studen> </college> Example txt = xmlDoe-getElementsByTogName(‘rstname")[0}.childNodes[0}.nodeValue; W_ Internet Program une (MU) 3 yn PUP and XML Explanation of Example © XML DOM ol sgetElementslhy Ty el hy the parser lame( "ttle" [0] - get the first <title> elem ‘childNodes{0] - the first child of the <title> el 8 (the text node) 5.1.12 Programming Interface can be accessed with JavaScript or other +The DOM moilels XML as a set of node objects. The nodes avaSeript. programming languages. In this tutorial we use ‘© The programming interface to the DOM is defined by a set standard properties and methods, + Properties are often referred to.as something that Is (le. nadename ts “book”) * Methods are often referred! to as something that Is done (Le. delete *book”) XML DOM Properties ‘These are some typical DOM properties xcnodeName - the name of x x.nleValue - the value of x xparentNode «the parent node of x xcchileNodes - the ebill nodes of x =the attrib sat alone : 4 INote : _In tho list above, xis a node object XML DOM Methods a.getElementsBy/TagName(aume) - ge all elements with a specified t sx.appendChild(ede) + insert a child node tox (noc) ~ remove a child node from x 5.1.13 XML Parser XML Parsers are software libraries or packages that allow client applications to interact with XML. documents. Checks the format of the XML document as well as validates it if necessary. Browsers today have XML parsers bullt- in.XML parsers convert XML into a readable format. Example XML Parser <!DOCTYPE heal > <huml> <body> <pid="demo"> </p> WF _Internet Programming (MU) 510 <eullege> <etudent> "4 *<fistnamne> Ram [fisiname>"+ *<lasiname>Habeja<astrame>" *<contaet> 09990149925 <Jeontact>"+ "-<email>ramBaheja@abe.com-<email>" “<Istadent> </ellege>" parser = new DOMParser; umDoc = parser. parseFromStingltext,texUxn"); tcument getElement Di dems, nner ETL = smiDoc gtElementsBy/TagName( lstname’)[0.childNodes[0].nodeValue; <script <Ihoay> <I> Output Raheja Explanation of Example Atext string is defined: var text ="<college> <student>"+ “<firtname> Ram</frsiname>"+ *<lasiname> Raheja<asiname>" "-<contact> 09990149935 </conlact>"+ *<emsil>ramRaheja@abe.com</email>' "<(student> <Jcollege>" ‘An XML DOM parser is created: 1ew DOMParser)s parser ‘The parser creates a new XML DOM object using the text string: xmDoe = parser parseFromString(tex,text/eml" Web Extension PHP and XML, WG _Internet Programming (MU) 5-11 Web Extension PHP and XML 5.1.14 XSLT Example “The recommended style sheet language for XML is XSLT (eXtensible Stylesheet Language Transformations) XSLT is much more sophisticated than CSS. SLT allows you to add and remove elements and attributes from an ouput le ‘so, you can rearrange and sort elements, perform tests and make decisions about which elements to display and hide, and much more. XPath is used by XSLT to find information in an XML document. We will use the following XML document aml version="1.0°2> <amleatylesheet type <Callege> <name> Ramesh <Jname> <Subjerts2C programming <ISubjertn> <<obiies> Singing. </Mobhion> dent > -<Suudem> <name> Kam</name> <Subjectn> Python </Subjects> <Hobhies> Dancing.</Mobhies> </Sud </Colle xLsT <2aml version ="1.0> oxp/\999IXSLTransfocm"> _exnleatylesheet version ="10" xmlnss match ="7"> << xsl:templ <body> <inhpenlor= "4 Ines 2" > eth Subjerte<th> <i> WF _internet Programming (MU) 5-12 <u> <td> <ral-valuc-of select: CollegeiStudlenname"/> </td> ‘Std> <aslivaluc-of select="College/StudenySubjects"/> </td> </tr> Julte> <tedy> <I> </sh:template> S/ssl:stylesheet> 5.2 _ Introduction to PHP "does not have an intermediate compilation step. Scripting languages are used in web applications, Its used in server sid side scripting languages are: JavaScri Script ete, le as well as client side. Server. Pt, PHP, Perl ete, and client- side scripting languages are: JavaScript, VBS 5.2.2 Features of PHP language . Simple tis very simple and easy to use, used all over the world, Interpreted “ompared to another scripting language itis very simple and easy, this is widely {isan interpreted language, ie. there is no need for compilation, 3. Faster {tis faster than other scripting languages eg asp and sp 4. OpenSource pen source means you no need to pay for using PUP, you can free dawnload and use W_ internet Programming (MU) 5-13 Web Extension PHP and XML 5. Platform Independent PHP code will be run on every platform, Linux, Unix, Mac 0S X, Windows, Case Sensitive PHP is case sensitive scripting language at the time of variable declaration. In PHP, all keywords (e4. if, else, While, echo, etc), classes, functions, and user-defined functions are NOT case-sensitive, 5.3 Data Types, Control Structure, Built in Functions etc. 5.3.1 My First PHP program to print “Hello World” Example 5.3.1 <IDOCTYPE hum > <humi> <bouly> <hL1>My fist PHP Exampte</hl> <?php ‘echo "Weleome to PHP"; <fboiy> <ihunt> My first PHP page ita Code ‘Welcome To PHP! PHP Serpe Explanation of above Program ‘As you can see in the above example PHP script normally contains some HTML tags and some scripting code. We can put script anywhere in the document. APHP script starts with <?php and ends with?> Basic Syntax is as Follows: <<? phpllindicates stat of PHP code 11 PHP code goes here 2>Hfindicates end of PIP code “The default extension of PHP file is php. Above Example also uses builtin PHP function “echo” to print the text “Welcome to PHP* on the web page.IN PHP all the Statements ends with semicolons (;). ‘Web Extension PHP and Xt, WH _Internet Programming (MU) Sule 5.3.2 Comments in PHP stand: Comments are the non-executable program statements written to make the program more understandable ang readable. Comments Let others understand your code. Comments also useful to remind yourself a you did - IF programmer is coming back to their work a year or two later and has to re-figure out what they did. Comments can ‘remind him of what he was thinking when he wrote the code. Example 5.3.2 <!DOCTYPE himl> <html> <body> <?php ‘echo "// symbol is used for single line comment 11 This is a single-tine comment echo" <br>" echo “# symbol is used for single line comment “ 4# This is also a single-line comment cecho"<br>"; echo "/* */ symbol is use for multiple line comment "; ‘multiple lines of comments */ <i> <tt> F Example of Commnets in PHP ‘syrubo is used for singe line comment symbol suse fr sig ne comment symbol sus for mil ie nnment Explanation: The above program shows us how to add single and mult-fine comments to PHP scripts. Single-line comments can be added with // (double black slash) and # (hash). In multiline comments, symbol) can be used. */ (a star symbol anda slash PR ee (WF Internet Programming (MU) 5-15 Web Extension PHP and XML 5.3.3 Variable in PHP In programming, variables are used to hold information. A variable is a name that represents a value. Variables are used to store data, such as numbers, characters, strings, and memory addresses, so that we can use them in other parts ofthe program. In PHP, a variable starts with the $ (dollar) sign, followed by the name of the variable: Example 5.3.3 : Variable in PHP <!DOCTYPE hml> <html> <h1> Variable Demo </h1> <body> <?php Sstr = "Sting Variable!"s//Assi ng String to the vari integer number tothe variable Sdecimalno = 10.5y/Assigning decimal no tothe variable echo $str, Displaying Value of variable echo" <br>"; echo $num; echo "<br>"; echo Sdecimalno; S tondy> </html> Variable Demo Sting Variable! 5 10.5 Explanation Asa result ofthe statements above, the variable Sstr will hold the value String Demo! the variable Snum will | the value 5, and the variable $decimal no will hold the value 10.5. To assign text values to variables, you must quotes around them. As we have done for variable $str. There is no separate command in PHP for declaring vari like in other programming languages. They are created when a value is assigned to them. WF _ internet Programming (MU) 5-16 Web Extension PHP and xMp Rules for PHP variables * Avariable can have a short name (like a and b) or a more descriptive name (age, firstname, marks). * Avariable start with the $ sign, followed by the name of the variable * Avariable name must start with a letter or the underscore character * Avariable name cannot start with a number Avariable name can only contain alpha-numeric characters and underscores (A-z,0-9, and _) Variable names are case-sensitive (Sage and SAGE are two different variables) Example 5.3.4 : Displaying value of variable !DOCTYPE buml> <html> <<h1> Displaying value of varable</h1 > <body> <?php $str = "Variable Demo"; echo "Variable str contains ‘$str! value"; > <Ivody> </humnl> Example 5.3.4 shows how to display value ofthe variable on the screen Displaying value of variable ‘Variable tr contains Variable Demo! value Explanation value and text as well. Example 5.3.5 : Example Adding two numbers <!DOCTYPE huml> Pf <html> <h1> Example adding two numbers </h1> <body> <?php Web Extension PHP and XML W_ internet Programming (MU) of x= x <br>"; e+ fy cho "Value of = 8; > <liy> <fint> Example adding two numbers Value of x= 5 Value of x= 5 Value of = 9 Explanation ‘The data types of the variables x, y, and z have not been declared in the example above. PHP automatically assigns a data type to the variables based on their values. Due to the fact that the data types are not set up strictly, you can add a string to an integer without causing an error. In PHP 7, type declarations were added. This allows you will throw a to specify the data type expected when declaring a function, and by enabling the strict requirement "Fatal Erro Ifa type mismatch occurs. 5.3.4 PHP Data Types ‘Avariable can store various types of data, and different types of data can perform different tasks. ‘The following data types are supported by PHP: String Integer Float (floating point numbers - also called double) Boolean 1 2 3. 4 5. Array 6. Object 7. NULL 8. Resource 1, PHP String ‘The term string refers to a sequence of characters, such as "String in PHP!". Web Extension PHP and 14, SF_ internet Programming (MU) Strings can be any text enclosed in quotes. 'up to you whether to use single or double quotations Example <Iphp Setel = "Sarin in PHIDY"; $su2 = Sequence of characters"; echo Sstrl; echo "<br>" echo $2 ; PHP Integer ‘The integer data type represents a non-decimal number between -2,147,483,648 and 2,147,403,647. Forintegers, follow these rules: (a) Atleast one digit must be present in an integer (b) Integers cannot have decimal points (©) An integer can be either positive or negative (4 You can specify integers in decimal (base 10), hexadecimal (base 16), octal (base 8), or binary (base 2) notation & is an integer in the following example. The PHP var.fun () function returns the following data types and values : Example <?php $= 500; echo “value of xis =Sx<be>' ‘ar fun($s) dpassing value of vatiable x tothe function var fun ‘Uldisplaying the value of integer variable x ‘value of oat variable x is =8x<he>"\/deplaying the value of integer variable x var fun(8s); /passing value of variable x wo the function var fun > 4, PHP Boolean A Boolean represents two possible states: TRUE or FALSE. SF _ Internet Programming (MU) 519 ‘Web Extension PHP and XML. 5. PHP Array An array stores multiple values in one single variable. In the following example Sstudent is an array. The PHP var_fun () function retums the data type and value: Example <2 Sstudent var_fun (Student) 2 = array("ram",/ramesh""radha’,'"radhika"); ‘You will earn a lot more about arrays later in this chapter Example 5.3.6 : Data types in PHP <!DOCTYPE himl> <himl> ‘<h2>Data types in PHP</h2> <body> <2php echo “Displaying value of string variable<br>"; Svar="var is string"/fhere var is assigned a string value so datatype of var is string echo Svar; echo"<br>": echo “Displaying value of Integer variable<br>"; ‘Svar=Sy/here varis assigned a imeger value so data type of var is integer echo Svar; cecho"<br> cccho “Displaying value of Float variable <br>"; ‘$var=55.5u//here var is assigned afloat value so data type of var is loat echo vars echo"<br>"; ‘echo “Displaying value of Boolean variable<br>"s S$ear=tuey/here var is assigned a Boolean value so datatype of Boolean is integer echo Svar, echo! <br>": > </body> </ol> ion PHP ¥F_Imernet Programming (MU) 5:20 et ers PP and Output Data types in PHP Displaying value of string variable var is string - Displaying value of Integer variable 5 Displaying value of Float variable 55.5 Displaying value of Boolean variable 1 indicates True Value 1 5.3.5 PHP Operators Operators are used to perform operations on variables and values, PHP divides the operators in the following groups: + Arithmetic operators * Assignment operators + Comparison operators * _Increment/Decrement operators + Logical operators + String operators + Array operators * Conditional assignment operators 1. Arithmetic operators addition, subtraction, multiplication etc. Operator | Name Example | Result + Addition Sx+8y__ | Sum of $x and sy : Subtraction | $x-8y _| Difference of and $y Multiplication | $x*$y | Product of $xand $y 1 Division $x/$y _ | Quotient of $x and sy % Modulus Sx%Sy_| Remainder of $x divided by $y Exponentiation | $x** $y Result of raising $x to the $y'th power &_ Internet Programming (MU) 5-21 Web Extension PHP and XML Example 5.3.7 : Arithmetic operators <!DOCTYPE hum > <himl> Sh2> Arithmetic Operator += * 4 #*</h2> <body> <?php Sx = 10; Sy =6; $2=8x + Syu/Addition operator ‘echo “Addition of X and Y is = $2 <BR>"; $2=8x - $y://Subtraction operator echo “Subtraction of X and Y is = $2 <BR>"; § sx * Sy://Multiplication operator echo “Multiplication of X and Y is = $2 <BR>"; =} sx / $y://Division operator echo “Division of X and Y i $2 <BR>"; $2=8x % Syy/Modulus operator echo “Modulus of X and Y is = $2 <BR>"; $2=$x ** $y://Exponential operator ‘echo “Exponential of X Raise to Y is = $2 <BR>"; > </body> </html> Airthmetic Operator + - * / % ** Addition of X and Y is= 16 Subtraction of X and Y ‘Multiplication of X and Y is= 60 Division of X and Y is = 1666666666667 Modulus of X and Y is =4 Expovential of X Raise to Y is= 1000000 isin WF _Internet Programming (MU) 5.22 2. PHP Assignment Operators Web Extension PHP and XML The PHP assignment operators are used with numeric values to write a value to a variable, ‘The basic assignment operator in PHP is ” assignment expression on the right. It means that the left operand gets set to the value of the Assignment | Same as... Description xy x=y__ | Theleft operand gets set to the value of the expression on the right xesy Addition xy Subtraction y Multiplication x/y Division x%=y Modulus Example 5.3.8 : Assignment Operator ‘<!DOCTYPE himl> <himl> wment Operator </h2> § += 100y/Composite Assignment (Addition) Operator += performs x=x-+100; echo "X=8x<br>"; 8y=30; 8y-=10,/Composite Assigament (Subtraction) Operator performs y echo "Y=8y <br>", 210; $2°=24)Composite Assignment(multiplcaton) Operator *= performs echo "Z=$2<br>", $m=50; $n/=5y/Composite Assignment (Divisi echo 'M=$m<br>", $n=15; $09%=21/Composite Assignment (Modulus) Operator 96= performs n=n2; echo "N=Sn<br>"; 2 <Mbody> Operator /= performs m=n/5; </humt> ay W_imernet Programming (MU) Assignment Operator X = 120 Y = 20 = 20 = 10 e1 zEn 3. PHP Comparison Operators Web Extension PHP and XML ‘The PHP comparison operators are used to compare two values (number or string): Operator Name Example Result Equal ‘$x==$y | Returns true if $xis equal to Sy dential Returns true if $xis equal to $y, and they are of the same type Not equal Returns true if $x is not equal to $y 2 Not equal Returns true if $x is not equal to $y Not identical Returns true if $x is not equal to $y, or they are not of the same ype > Greater than $x> Sy _| Returns true if$x is greater than $y < Less than $x<$y__| Returns true if $x is less than Sy Greater than orequalto | $x>=Sy_| Returns true if$xis greater than or equal to Sy Less than or equalto | $x<=$y_| Returns true if$xis less than or equal to $y <= Spaceship $x<=> $y | Returns an integer less than, equal to, or greater than zero, depending on if $x is less than, equal to, or greater than Sy. Introduced in PHP 7. 4, PHP Increment / Decrement Operators ‘The PHP increment operators are used to increment-a variable’s value. The PHP decrement operators are used to decrement a variable’s value. Operator | Name Description 4++$x__| Pre-increment | Increments $x by one, then returns $x $x++ | Post-increment | Returns $x, then increments $x by one ~-$x__| Pre-decrement_| Decrements $x by one, then returns $x $x-__| Post-decrement | Returns $x, then decrements $x by one F_internet Programming (MU) 5-24 Web Extension PHP and x —=—— Example 5.3.9: Increment/Decrement Operartor <!DOCTYPE himl> <himl> ‘<h2>Increment Decrement Operator</h2> <body> <?php $x = 10; 8y= } $2=10; w= 05 ‘echo "Pre-Increment”; echo ++8x s/Pre-Inerement echo" <br>"; {echo “post-Increment'secho 8) ++://post-Inerement echo" <br>"; echo "Pre-Deerement”; echo ~B1:/[Pre-Decrement echo "post-Decrement"; echo $w—V/post-Decremem echo"<br>", echo" <br> *, 2> </body> </html> Increment Decrement ‘© Pre-increment 11 Post-Increment 10 Pre-Decrement 9 Post-Decrement 10 5. PHP Logical Operators ‘The PHP logical operators are used to combi combine more than one conditional statements. Foll ine conditional statements. By using logical operator, we can lowing i the list of logical operators supported by PHP Operator | Name | Example Result And__| And_| $xand $y | True ifboth $x and $y are true or Or | Sxor$y | Trueifeither $x or $y is true Xor_| Xor_| Sxxor$y | Trueifeither $x or $y is true, but not both && | And | $88 sy | True ifboth $x and $y are true i Or | Sxilsy_| Trucifeither $x or $y is true ! Not_| 'x__ | Trueifsxisnot true od SF _Internet Programming (MU) 5-25 Web Extension PHP and XML Example 5.3.10 : logical Operator <!DOCTYPE himl> <himl> <h2> PHP logical Operator</h2> <body> <?php $x = 100; Sy if ($x 30; }00 and $y 50) { ‘echo "Both the conditions are true thtas why result of logical AND operat } if is true <br> 100 or $y 50) ‘echo "Both the conditions are true thtas why result of logical OR operator is true"; in 100 Xor $y == 50) echo "Both the conditions are true thtas why result of logical OR operator i true > </body> </html> Output PHP logical Operator © Both the conditions are true thetas why result of logical AND operator is true. «Both the conditions are true thtas why result of logical OR operator is true ‘The Condition ($x=100 and $y=50) is true, that why respective message in if block is executed Condition (Sx=100 OR Sy=50) is true, that’s why respective message in if block is executed, Condition (Sx=100 Xor Sy=50) is true, that’s why respective message in if block is not executed. 6. PHP String Operators PHP has two operators that are specially designed for strings. Operator Name Example Result Concatenation Sext1 .$ext2_| Concatenation of $txt1 and $vt2 = | Concatenation assignment | Stxt1 .= $txt2 | Appends Stxt2 to $txt1 WH toveroet Programming (MU) 5-26 Web Extension PHP and XML, Example 5.3.11 : String Operator <!DOCTYE html> <himl> <<h2> string concatination using string operator </h2> <body> <2php Seal "Sting Concatination’ $ext2 = " Using dot operator; echo Stat] . $1025 > </body> </ul> string concatenation using string operator string concatenation Using dot operator 7. PHP Array Operators ‘The P/HP array operators are used to compare arrays. Operator| Name | Example Result + Union $x+Sy [Union of Sx and sy Equality | $x=: [Returns true if $x and Sy have the same key/value pairs Identity [Returns true if $x and Sy have the same key/value pairs in the same order| land of the same types t= | Inequality [Returns true if$x is not equal to $y <> _| inequality [Returns true if$x is not equal to $y Non-identity Returns true if $x is not identical to $y 8. PHP Conditional Assignment Operators ‘The PHP conditional assignment operators are used to set a value depending on conditions Operator Name Example Result OA Ternary Sx= expr? expr2:: expr3_| Returns the value of $x. ‘The value of $x is expr2 if expr = TRUE. ‘The value of $x is expr3 if expr! “ALSE Wises WF_Internet Programming (MU) 7 Web Extension PHP and XML perator Name Example Result Null coatescing Sxzexpri Nexpr2 | Returns the value of Sx. The value of Sx Is expr fexpri exists, and is not NULL. Iexprt does not exist, oF is NULL, the value of Sx Is expr2. Introduced in PHP 7 Example of Ternary Operator 5.3.6 Control Structure * In computing, control flow is the flow of instructions in which they are executed. Programs use Control Structures to specify the flow of control. + Itis much easier to understand any algorithm or program ifit uses self-contained modules called logic or control structures. Based on certain parameters and conditions, it analyses a program's flow and determines how to proceed. There are three types of logic flow: (A) Sequence logic, or sequential flow (B) Selection logic, or conditional flow (C) Iteration logic, or repetitive ow (A) Sequential Control Structure ‘The instructions are executed in the sequence they have written. Simple program of addition of two numbers is the example of sequential control structure. (B) Selection logic, or conditional flow In selection logic or conditional flow, the instructions are executed best on the result of some condition. It's very common when you write code to perform different actions depending on the situation. You can use conditional statements in your code to do this. In PHP we have the following conditional statements : + ifstatement- executes a piece of code ifa condition is true «© ifcelse statement executes a piece of code ifa condition is true and another piece code if that condition is false executes different codes for more than two conditions If.elseif.,else statement - © switch statement - selects one of many blocks of code to be executed Yai Internet Programming (MU) Web Extension PHP and XML. : ‘The if statement executes some code if one condition is true. Syntax if (condition) { code to be executed if condition is true; } Example 5.3.12 : if statement <!DOCTYPE himl> Be Cue ‘Sage = 28; if Gage >= 18) { echo "You are eligible for vatin } 2> <body> </html> You are eligible for voting 2. PHP -- The if..else Statement ‘Theif.clse statement executes some code ifa condition is true and another code if that condition is false. Syntax if (condition) { code to be executed if condition is true; Felse { code to he executed if condition is false; d Example 5.3.13 :Ifelse statement <{DOCTYPE huml> <himl> ‘<h2> Example of if condition </h2> <body> Internet Programming (MU) SS Web Extension PHP and XML ocho "You are eligible for votin ) else( ‘echo "You are not eligible for voting"; } > </body> </htl> You are not eligible for voting 3. PHP - The if..elseif..clse Statement ‘The if..clseif..clse statement executes different codes for more than two conditions. Syntax if (condition) { code to be executed if this condition is tues } elseif (condition) { code to be executed if frst condition is false and this condition is trues }else { code to be executed if all conditions are false; , 5.3.7 Developing Web Application Using PHP 1. Introduction ‘To begin with we Need to know following Basic technologies required to develop Web Application Using PHP (2) HTML is the markup language used for structuring and presenting content on the World Wide Web. (Done in chapter 1) (©) 58+ describes how HTML elements are to be displayed on a screen, paper, oF In other media, (Done in chapter 1) (0) PHP: is a highly popula features. Itis the fastest resource aval (d) MySQL :is a database management ‘system bas applications (Will earn inthe later inthis chapter) + server-side scripting language. It is very flexible and has a lot of Innovative Jable for creating database-enabled dynamic websites ed on Structured Query Language (SQL) which is used in web WW _Internet Programming (MU) 5-30 Web Extension PHP and XML nt ee For front end development we will require HTML & CSS For Back-end Development we will require PHP & MySQL Following is the list of the software which we will require for development of web application using PHP & MySQL. (@) Text Editor (HTML and Css) (b) Web Server (PHP) (©) Back End Database (MySQL) (@ Web Browser ‘Text Editor : First, you will need a text editor to create and edit your program. There are many options on the Internet, but prefer to use notepadd++ because itis free and easy to use. Local host: Typically, the local host in computer networking is the computer you are working on, also called “this PC". Local is useful for testing purposes if you are a developer, network administrator, localhost most often when creating web aj development process, Developers use ipPS or programs that require an internet connection. As part of the ‘we test the application on localhost to ensure that it functions properly. Setting up Server Having PHP and MySQL installed on your system is necessa server on which we are going to run our application, eis possible to use XAMPP (Cross-Platform, Apache, MYSQL, Perl, PHP) because it installs both PHP and MySQL for us ry to work on it locally. The first step is to have a Once you have done with installation part, You should go tothe directory where you installed KAMPP perform following steps. (2) goto htdocs folder. C:\Program Files\XAMPP\htdocs (b) Inside of your htdocs, you should create your folder. C:\Program Files\KAMPP\htdocs\my folder (2 Then, open your Notepadd++ and create anew file inside the folder and nameit C:\Program Files\KAMPP\htdocs\my_folder\ (4) Inside the fle Write your code and save it as php extension ‘Web Application for Alumni registration using PHP. Alumni students will be able to register themselve es to the college database online, collect data on thetr alumni students through the and colleges will be able to web application, Welte down th following Code in Text Editor and Save it By Registration php <himl> <heal> Stitle> Alunini Registration Form Java Script For Form Validation function form validator) { |=document frm] txtinm.valu lert(Enter some frst name."), document fem] tstfnm. focus; etum false; } else { Iaten(aaadds”); Aocument. frm action="bup/flocalhostSampte efadd_alu.php"s documentfrm1.submit(s return true wv F_ Internet Programming (MU) ‘center"> Alumni Registration Form Web Extension PHP and XML Internet Programming (Mu) “esh> Year of Passing ceclect name=yop> PHP Script for Year of $x", echo "The number is: $x
", } > <
teurroceu> =txteomp> ‘
First Name
Last Name Address Mobile Number Email Department
Current Occupation <> Name of Industry/Others "Electronics & Telecommunication">Electronies & Telecommunication Tate Web Extension PHP and XML 4 Internet Programming (MU) 3 <Designation Company's Address