Page 76 - Open Soource Technologies 304.indd
P. 76

Web Technologies-I



                   Notes         3.6.1 XML Style
                                 Because of the advent of the eXtensible Markup Language (XML) and the migration of HTML to
                                 an XML language (XHTML), the currently preferred technique for embedding PHP uses XML-
                                 compliant tags to denote PHP instructions.
                                 Coming up with tags to demark PHP commands in XML was easy, because XML allows the
                                 definition of new tags. To use this style, surround your PHP code with <?php and ?>. Everything
                                 between these markers is interpreted as PHP, and everything outside the markers is not. Although
                                 it is not necessary to include spaces between the markers and the enclosed text, doing so improves
                                 readability. For example, to get PHP to print “Hello, world”, you can insert the following line
                                 in a web page:
                                 <? php echo “Hello, world”; ?>
                                 The trailing semicolon on the statement is optional, because the end of the block also forces the
                                 end of the expression. Embedded in a complete HTML file, this looks like:



                                 <! doctype html public “-//w3c//dtd html 4.0 transitional//en”>
                                 <html>
                                 <head>

                                 <title>This is my first PHP program!</title>
                                 </head>
                                 <body>

                                 <p> Look, ma! It is my first PHP program :< br />
                                 <? php echo “Hello, world”; ?>
                                 <br /> How cool is that? </p>

                                 </body>
                                 </html>
                                 Of course, this is not very exciting—we could have done it without PHP. The real value of PHP
                                 comes when we put dynamic information from sources such as databases and form values into
                                 the web page. Let’s get back to our “Hello, world” example. When a user visits this page and
                                 views its source, it looks like this:



                                 <! doctype html public “-//w3c//dtd html 4.0 transitional//en”>
                                 <html>
                                 <head>
                                 <title>This is my first PHP program!</title>
                                 </head>

                                 <body>
                                 <p>
                                 Look, ma! It is my first PHP program:<br /> Hello, world!<br /> How cool is that?
                                 </p>



        70                                LOVELY PROFESSIONAL UNIVERSITY
   71   72   73   74   75   76   77   78   79   80   81