W2 Lesson 2 PHP Basics - Presentation
W2 Lesson 2 PHP Basics - Presentation
PHP Basics
Objectives
• At the end of the module the student is expected to:
• Understand how to use PHP Syntax
• Understand and apply comments in PHP codes.
• Understand the concept of case sensitivity in PHP codes.
• Understand the use of variables.
• Understand and apply the use of echo and print
statements
• Understand the concept of data types and use it in PHP
programs
• Apply string concatenation
PHP BASICS
PHP Syntax
To embed PHP code, you must use the following syntax.
<?php
// PHP code goes here
?>
Every time you want to use php scripts, the codes must be enclose
inside <?php ?> , all codes that are place inside the php block are read
by the php.
PHP Comments
• A comment in PHP code is a line
that is not read/executed as part of
the program. Its purpose is to
provide information or details to the
codes.
• The following are the use of
comments.
• Let developers understand the code
you are writing.
• Serves as a reminder.
PHP Case Sensitivity
• In PHP, all keywords (e.g. if,
else, while, echo, etc.),
classes, functions, and user-
defined functions are NOT
case-sensitive. In the example
below, all three echo
statements below are legal
(and equal):
PHP Case Sensitivity
• Note: all variable names
are case-sensitive. In
the example below, only
the first statement will
display the value of the
$color variable (this is
because $color,
$COLOR, and $coLOR
are treated as three
different variables):
PHP Variables
• A variable can have a short name (like x and y) or a more descriptive
name (age, carname, total_volume).
• Rules for PHP variables:
• A variable starts with the $ sign, followed by the name of the
variable
• A variable name must start with a letter or the underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive ($age and $AGE are two
different variables)
• Note: Remember that PHP variable names are case-sensitive
PHP Variables
PHP Data Types
PHP Data Types
PHP Variables
PHP Variables
String Concatenation
• 2. The customer should be able to enter their first and last name in
separate fields
• 3. Let the customer make a choice on whether they would like to be
contacted with their phone number or email and let them enter that
information only.
• 4. DU30 Real Estate only serves the following cities: Manila, Cebu,
and Davao. They
• should only be able to choose among those cities for potential places
to live.
• 5. Allow the user to enter comments.
• 6. Prove a submit button to send this information to the server.
MACHINE PROBLEM