Creating PHP Pages Chapter 5 PHP Structure and Syntax.

10
Creating PHP Pages Creating PHP Pages Chapter 5 Chapter 5 PHP Structure and PHP Structure and Syntax Syntax

description

Basic PHP Scripts The Web page generated from the PHP code, and XHTML elements found within the PHP file, is returned to the client A PHP file that does not contain any PHP code should be saved with an.html extension.php is the default extension that most Web servers use to process PHP scripts

Transcript of Creating PHP Pages Chapter 5 PHP Structure and Syntax.

Page 1: Creating PHP Pages Chapter 5 PHP Structure and Syntax.

Creating PHP PagesCreating PHP Pages

Chapter 5Chapter 5PHP Structure and SyntaxPHP Structure and Syntax

Page 2: Creating PHP Pages Chapter 5 PHP Structure and Syntax.

Basic PHP ScriptsBasic PHP Scripts

• Embedded language refers to code that is embedded within a Web page (HTML/XHTML document)

• PHP code is typed directly into a Web page as a separate section

• Server recognizes embedded script and executes

• A Web page containing PHP code must be saved with an extension of .php to be processed by the scripting engine

• PHP code is never sent to a client’s Web browser; only the output of the processing is sent to the browser

Page 3: Creating PHP Pages Chapter 5 PHP Structure and Syntax.

Basic PHP ScriptsBasic PHP Scripts

• The Web page generated from the PHP code, and XHTML elements found within the PHP file, is returned to the client

• A PHP file that does not contain any PHP code should be saved with an .html extension

• .php is the default extension that most Web servers use to process PHP scripts

Page 4: Creating PHP Pages Chapter 5 PHP Structure and Syntax.

Creating PHP Code BlocksCreating PHP Code Blocks

• Code declaration blocks are separate sections on a Web page that are interpreted by the scripting engine

• There are four types of code declaration blocks:• Standard PHP script delimiters• The <script> element• Short PHP script delimiters• ASP-style script delimiters

Page 5: Creating PHP Pages Chapter 5 PHP Structure and Syntax.

Standard PHP Script DelimitersStandard PHP Script Delimiters

• All scripts start with <?php and end with ?>

• Program lines end in ";" or you get an error

• Code block: { //code here } (brace brackets)

• White space is generally ignored (not in strings)

• Comments are created using:• // single line quote• /* Multiple line block quote */

Page 6: Creating PHP Pages Chapter 5 PHP Structure and Syntax.

The <script> ElementThe <script> Element

• The <script> element identifies a script section in a Web page document

• Assign a value of "php" to the language attribute of the <script> element to identify the code block as PHP

Page 7: Creating PHP Pages Chapter 5 PHP Structure and Syntax.

Short PHP Script DelimitersShort PHP Script Delimiters

• The syntax for the short PHP script delimiters is<? statements; ?>

• Short delimiters can be disabled in a Web server’s php.ini configuration file

• PHP scripts will not work if your Web site ISP does not support short PHP script delimiters

• Short delimiters can be used in XHTML documents, but not in XML documents

Page 8: Creating PHP Pages Chapter 5 PHP Structure and Syntax.

ASP-Style Script DelimitersASP-Style Script Delimiters

• The syntax for the ASP-style script delimiters is<% statements; %>

• ASP-style script delimiters can be used in XHTML documents, but not in XML documents

• ASP-style script delimiters can be enabled or disabled in the php.ini configuration file

• To enable or disable ASP-style script delimiters, assign a value of “On” or “Off ” to the asp_tags directive in the php.ini configuration file

Page 9: Creating PHP Pages Chapter 5 PHP Structure and Syntax.

ParsingParsing

• How the browser can read a text file and process it, that's a basic parsing method.

• Browsers parse web pages as they load• Web servers with server side technologies like PHP parse web pages as

they are being passed out to the browser• You can embed sections of PHP inside html :

• Or you can call html from PHP :

<BODY><p><?php $test = "Hello World!";echo $test;</p></BODY>

<?phpecho "<html><head><title>Howdy</title>…?>

Page 10: Creating PHP Pages Chapter 5 PHP Structure and Syntax.

ReferencesReferences

References :

1.Anonymous.(n.d.). Apache HTTP Server Documentation Version 2.2. Retrieved from http://httpd.apache.org/docs/2.2/.2.Achour, M., Betz, F. (n.d.), PHP Manual. Retrieved from http://www.php.net/download-docs.php.3.Anonymous. (n.d.). MySQL Reference Manual. Retrieved from http://downloads.mysql.com/docs/. 4.Naramore, E., Gerner, J., Le Scouarnec, Y., Stolz, J., Glass, M. K. (2005). Beginning PHP5, Apache, and MySQL® Web Development. Indianapolis, IN: Wiley Publishing, Inc.