17
Writing Web Pages By Shyam Gurram

Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

Embed Size (px)

Citation preview

Page 1: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

Writing Web PagesBy

Shyam Gurram

Page 2: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

Agenda

• Writing Web Pages

• Delimiting PHP Program Units.

• Displaying Output to Web Pages

• Putting Comments in PHP Programs

Page 3: Writing Web Pages By 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.

Page 4: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages 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.

Page 5: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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.

Page 6: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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>.

Page 7: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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 ?>.

Page 8: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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.

Page 9: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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.

Page 10: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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.

Page 11: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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.

Page 12: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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)

Page 13: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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)

Page 14: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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

Page 15: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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)

Page 16: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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.

Page 17: Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs

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. */