Introduction to PHP.

Introduction to PHP.

Output.

Any output of a PHP script becomes part of the document the PHP preprocessor is writing.

All output must be in the form of HTML which may include embedded client-side scripts



There are three forms of producing output in a PHP script

echo, print, and printf

  1. echo
    • Can be called without parenthesis around several parameters

      echo "A rose by any other name <br />", "Is a rose <br />";
              


    • If parenthesis are used, only a single parameter is allowed


    • echo does not return a value


  2. print
    • Can never be called with more than one parameter


    • It returns a value: 1 if succeeded; 0 if failed


    The following example displays the day of the week using date function:
    • l requests the day of the week


    • F requests the month


    • j requests the day of the month


    • S gets the correct ordinal suffix
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//EN"
    "http://www.w3.org/TR/xhtml1/dtd/xhtml1-strict.dtd">
    
    
    <!-- today.php
    	A trivial example to illustrate a php document
    	-->
    
    <html>
    <head>
    <title>
    today.php</title>
    </head>
    <body>
    
    <p>
    <?php
    	print "<b>Welcome to my home document <br /><br />";
    	print "Today is: </b>";
    	print date("l, F jS");
    	print "<br /><br />";
    ?>
    </p>
    </body>
    </html>
    

    A trivial example to illustrate a PHP document



  3. printf
    • Used to control the format of the displayed data


    • For more details look at any book on C

| Origins and Uses of PHP | | Overview of PHP | | General Syntactic Characteristics |
| Primitives, Operations, and Expressions | | Output | | Control Statements |
| Arrays | | Functions | | Pattern Matching |
| Form Handling | | Files | | Cookies | | Session Tracking |