writing web pages by shyam gurram. agenda writing web pages delimiting php program units. displaying...
TRANSCRIPT
Writing Web PagesBy
Shyam Gurram
Agenda
• Writing Web Pages
• Delimiting PHP Program Units.
• Displaying Output to Web Pages
• Putting Comments in PHP Programs
Writing Web Pages
• As we said discussed in the previous chapter, PHP is a server-side scripting or programming language. The primary purpose of server-side programming language is to generate HTML web pages. This language can be used to generate a complete a web page but is generally used as part of static or dynamic web page.
• We need to learn the following concepts to create a Web pages in an effective manner.
Delimiting PHP program units.
Displaying output to web pages.
Putting comments in PHP programs.
Delimiting PHP Program Units.
• We have four possible styles to use for embedding PHP in your web pages.
Default style ( Using the tags <? php and ?>)
HTML style script delimiters (<script language = “PHP”> and </script>)
Short tags (<? and ?>)
ASP-style tags (<% and %>)
• Among the four short tags and ASP-style tags save very little and present more issues than benefits.
Default Style
• <html>
<head>
<title>
PHP info test page
</title>
</head>
<body>
<?php phpInfo(); ? >
</body>
</html>
• The default syntax for embedding PHP programming units in your web page is the <?php and ?>.
• PHP Program consists of single statement followed by a semicolon.
Delimiting PHP Program Units Conti..
• <html>
<head>
<title>
PHP info test page
</title>
</head>
<body>
<script language=php >
phpInfo();
</script>
</body>
</html>
• PHP also supports a script delimiter.
• The Scripting syntax for embedding PHP programming units in our web pages consists of the<script language=“php”> and </script>.
Delimiting PHP Program Units Conti..
• <html>
<head>
<title>
PHP info Short-tag test page
</title>
</head>
<body>
<? phpInfo(); ?>
</body>
</html>
• PHP supports short tags provided you enable them in the php.ini configuration file.
• Short tags will have a little advantage and can lead to confusion, if you want to use them, the scripting syntax uses <? And ?>.
Delimiting PHP Program Units Conti..
• <html>
<head>
<title>
PHP info Short-tag test page
</title>
</head>
<body>
<% phpInfo(); %>
</body>
</html>
• PHP supports Micro ASP page syntax, in order to use the ASP page you need to enable in the php.ini configurations script by editing the asp_tags directive.
• If you want to use them scripting syntax uses <% and % >.
• If you chose to enable asp_tags in your php.ini file, you will need to restart your HTTPD for those changes to take effect.
Displaying Output to Web Pages
• There are two predefined PHP constructs and functions are used to display output to web pages.
• The difference between a function and a construct is that the parentheses are unnecessary in a construct.
• The first constructor is the echo() statement. General syntax for the echo statement is
void echo(string arg1 [, string arg2…])
• The limitation of the echo() constructor is that it returns nothing and therefore cannot be used in complex expression.
Displaying Output to Web Pages
• <html>
<head>
<title>
PHP echo() construct test page
</title>
</head>
<body>
<?
echo(“Hello one ! <br>”);
echo “Hello Two! <br>” ; ?>
</body>
</html>
• Each line that uses the echo() construct must be terminated by semicolon, which makes the lines statement of execution.
• In the echo() statement, if you want to pass multiple arguments to the ecjo command parentheses cannot be used.
Displaying Output to Web Pages
• There are several escape sequences that may likewise be included in the argument or argument list to the echo() construct.
• <br> is the web browser to perform a line break.
• The /t is the escape sequence for a tab.
• The /n is the escape for a new line.
• The \r is the escape sequence for a carriage return.
• The $ symbol is used to designate variables.
• The backslash is used to back-quote, and double quotes are used to delimit string values.
Displaying Output to Web Pages
• The second constructor is the print() statement.
• The benefit of the print() constructor is that it always returns an int value 1. This means that it used in complex expression.
• The difference between the print() and echo() construct is that the print() construct does not support multiple arguments with or without parenthesis.
int print(string arg)
Displaying Output to Web Pages
• There are two predefined PHP functions, they are printf() and vprintf().
• The printf() function outputs a formatted string.
printf(format, arg1, arg2, arg++)
• Required. Specifies the string and how to format the variables in it.Possible format values:
• %% - Returns a percent sign
• %b - Binary number
• %c - The character according to the ASCII value
• %d - Signed decimal number (negative, zero or positive)
Displaying Output to Web Pages
• %e - Scientific notation using a lowercase (e.g. 1.2e+2)
• %E - Scientific notation using a uppercase (e.g. 1.2E+2)
• %u - Unsigned decimal number (equal to or greather than zero)
• %f - Floating-point number (local settings aware)
• %F - Floating-point number (not local settings aware)
• %g - shorter of %e and %f
Displaying Output to Web Pages
• <?php$number = 123;printf("%f",$number);?>
• %G - shorter of %E and %f
• %o - Octal number
• %s - String
• %x - Hexadecimal number (lowercase letters)
Displaying Output to Web Pages
• The next function is vprintf() which is similar to printf().
• vprintf() returns a formatted string, Operates as printf() but accepts an array of arguments, rather than a variable number of arguments.
Putting Comments in PHP Programs
• The PHP programming language supports two styles of writing comments.
• Single-Lime Comment: These are used to comment the single line of code by using the forward slashes.
• // , # This is a single line comment
• Multiple-Line Comment: This is used to comment multiple lines of code.
• /* This is a multiple-line comment. */