PHP Statement Delimiter and Comments

This section provides a tutorial example on how to write PHP statements and comment in PHP source code files. PHP uses semicolon ';' as the statement delimiter. Comments can be entered in Perl, Java, or C styles.

PHP uses semicolon ";" as the statement delimiter. PHP statements can be written in the source code file in different ways:

If you want to enter comments into the PHP source code, you can do it in 3 ways:

Here is a tutorial example on how to write PHP statements and comments:

<?php
/* StatementSamples.php
#- Copyright 2003 (c) HerongYang.com. All Rights Reserved.
*/

# The next 1 statement is written in 2 code lines.
print "I am tossing a coin now. "
   . "Guess what the result will be?\n";

/* I am using the rand() function to simulate the randomness of
tossing a coin. The rand(min,max) function returns a random integer
between the specified minimum number and maximum number.
-- This is a sample of C style comment
*/

# The next 1 statement is written in 1 code line.
$count = 0;
while ($count < 7) {
   # Next 2 statements are written in 1 code line.
   $count++; print "Round # $count:\n";

   $coin = rand(0,1);
   if ($coin==1) {
      print "   Head\n"; // Java style comment
   } else {
      print "   Tail\n"; # Perl style comment
   }
}
?>

There is no surprises in the output:

herong> \php\php StatementSamples.php

I am tossing a coin now. Guess what the result will be?
Round # 1:
   Tail
Round # 2:
   Tail
Round # 3:
   Head
Round # 4:
   Tail
Round # 5:
   Tail
Round # 6:
   Head
Round # 7:
   Tail

Table of Contents

 About This Book

 Introduction and Installation of PHP

PHP Script File Syntax

 PHP Script Source Code File Format

 PHP Script Processing Rules

PHP Statement Delimiter and Comments

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Interface with Operating System

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 Managing File Upload

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Parsing and Managing HTML Documents

 Configuring and Sending Out Emails

 Image and Picture Processing

 Managing ZIP Archive Files

 Managing PHP Engine and Modules on macOS

 Managing PHP Engine and Modules on CentOS

 Archived Tutorials

 References

 Full Version in PDF/EPUB