ITE 216 – Applications Devt and Emerging Technologies
Prepared by: Arlene Mae C. Valderama
Module 3
Server Side Scripting using PHP
Learning Objectives:
At the end of this lesson, the students shall be able to:
1. Understand the context of server-side scripting using PHP.
2. Learn and use basic PHP syntax and its web-based programming
structure.
3. Apply PHP influencing scripting on programming.
UNIVERSIDAD DE MANILA 1
College of Computing Studies
Information Technology Department
SY 2025-2026
ITE 216 – Applications Devt and Emerging Technologies
Prepared by: Arlene Mae C. Valderama
What is PHP?
▪ PHP originally meant “Personal Home Page” as it was created in
1994 by Rasmus Lerdorf to track the visitors to his online resume.
▪ As its usefulness and capabilities grew (and as it started being used
in more professional situations), it came to mean “PHP: Hypertext
Preprocessor.”
PHP is an HTML embedded scripting language.
▪ HTML embedded means that PHP can be interspersed within HTML
which makes developing dynamic Web sites more accessible.
▪ PHP is scripting language as opposed to a programming language. It
is designed to do something only after an event occurs—for example
when a user submits a form or goes to a URL.
▪ PHP is a server-side, cross-platform technology. Server-side refers
to the fact that everything PHP does occurs on the server (as opposed
to the client, which is the Web site viewer’s computer). Its cross-
platform nature means that PHP runs on most operating systems,
including Windows, UNIX (any variants), and Macintosh.
▪ PHP scripts written on one server will normally work on another with
little or no modifications.
Basic Syntax
To place PHP code within a document, surround the code with PHP tags,
either the formal (XML style):
<?php
?>
or the informal:
<?
?>
UNIVERSIDAD DE MANILA 2
College of Computing Studies
Information Technology Department
SY 2025-2026
ITE 216 – Applications Devt and Emerging Technologies
Prepared by: Arlene Mae C. Valderama
▪ Anything placed within these tags will be treated by the Web server
as PHP (meaning the PHP interpreter will process the code rather
than it being immediately sent to the Web browser).
▪ PHP files must use an extension that the server knows to treat as a
PHP page. Standard HTML pages use .html or .htm extension and
normally, .php is preferred for PHP scripts.
Sending Data to the Web Browser
▪ PHP has a number of built-in functions written specifically, the most
common are echo() and print().
▪ First Example: Open text editor and type the code below. Save it as
“[Link]”.
<html> <head> <title> PHP Test: First Example </title> </head>
<body>
<?php
print "Hello World!<br>";
print "I'm in <b> UDM !</b><br>";
echo 'She said, "How are you?"<br>';
print "I'm just fine.<br>";
?>
</body>
</html>
▪ Using gmdate(): Open [Link] and add this line after the last print:
▪ Output of “[Link]”:
UNIVERSIDAD DE MANILA 3
College of Computing Studies
Information Technology Department
SY 2025-2026
ITE 216 – Applications Devt and Emerging Technologies
Prepared by: Arlene Mae C. Valderama
▪ Use the table below to modify date and time functions:
a Displays “am” or “pm”
A Displays “AM” or “PM”
d Gives the day of the month, 2 digits with leading zeros; that is, “01” to “31”
D Shows the day of the week, textual, 3 letters; for example “Fri”
F Displays month, textual, long; for example “January”
h Shows the hour, 12-hour format; that is “01” to “12”
H Shows the hour, 24-hour format; that is “00” to “23”
g Shows the hour, 12-hour format without leading zeros; that is “1” to “12”
G Shows the hour, 24-hour format without leading zeros; that is “0” to “23”
i Displays the minutes; that is “00” to “59”
j Gives the day of the month without leading zeros; that is “1” to “31”
l Gives the day of the week, textual, long; for example, “Friday”
L Boolean for whether it is a leap year; that is “0” to “1”
m Shows the month; that is “01” to “12”
n Shows the month without leading zeros; that is “1” to “12”
M Gives the month, textual, 3 letters; that is “Jan”
s Displays the seconds; that is “00” to “59”
S English ordinal suffix, textual, 2 characters; that is “th”, “nd”
t Shows the number of days in a given month; that is “28” to “31”
T Shows the Time Zone setting of the machine; for example, “MDT”
U Displays the seconds since the epoch
w Shows the day of the week, numeric; that is “0” (Sunday) to “6” (Saturday)
Y Displays the year, 4 digits; for example “2006”
y Displays the year, 2 digits; for example “06”
z Shows the day of the year; that is “0” to “365”
Z Gives the Time Zone offset in seconds; that is “-43200” to “43200”
UNIVERSIDAD DE MANILA 4
College of Computing Studies
Information Technology Department
SY 2025-2026
ITE 216 – Applications Devt and Emerging Technologies
Prepared by: Arlene Mae C. Valderama
Writing Comments
▪ PHP supports three comment types. First is similar to comments in
shell scripts (from Unix) and uses the pound or number symbol(#).
The second stems from the C++ programming language. The third
comment style—arising from C—allows for comments to run over
multiple lines. Examples, respectively:
# This is comment.
// This is also a comment.
/* This is a larger comment
that spans two lines. */
Using Variables
▪ Variables are widgets used to temporarily store values. These values
can be numbers, text, or much more complex arrangements. There
are eight types of variables in the PHP language. These include four-
scalar (single-valued) types—Boolean (TRUE or FALSE), integer,
floating point (decimals), and strings (text): two non-scalar (multi-
valued)—arrays and objects; plus resources. All variables in PHP
follow certain syntactical rules:
o A variable’s name must start with a dollar sign ($), for
example, $name.
o The name can contain a combination of strings, numbers,
and the underscore, example, $my_report.
o The first character after the dollar sign cannot be a number
(it must be either a letter or an underscore).
o Variable names in PHP are case-sensitive. So $name and
$Name are entirely different variables.
o Variables can be assigned values using the equals sign (=).
▪ STRINGS: A string is merely a quoted chunk of letters, numbers,
spaces, punctuation, etc. Below are examples of assigning a string
value to variables and printing out their values.
▪ Concatenating Strings: Concatenation is addition for strings and is
performed using the period (.). If assigning another value to an
existing variable, say ($book), the new value will overwrite the old
one. If concatenating one value to another, the concatenation
assignment operator (.=) is used.
▪ STRINGS: PHP has a slew of useful string-specific functions:
o strlen() – returns a number how long a string is (characters it
contain).
o strtolower() – returns a string converted entirely into lowercase
characters.
o strtoupper() – returns a string converted entirely into
uppercase characters.
UNIVERSIDAD DE MANILA 5
College of Computing Studies
Information Technology Department
SY 2025-2026
ITE 216 – Applications Devt and Emerging Technologies
Prepared by: Arlene Mae C. Valderama
o ucwords() – capitalizes the first character of every word.
Second Example: Open text editor and type the code below. Save it as
“[Link]”.
UNIVERSIDAD DE MANILA 6
College of Computing Studies
Information Technology Department
SY 2025-2026
ITE 216 – Applications Devt and Emerging Technologies
Prepared by: Arlene Mae C. Valderama
▪ Output of “[Link]”:
▪ NUMBERS: PHP has both integer and floating-point (decimal)
number types. Some number functions are round()are
number_format(). Example:
$n = 3.14;
$n = round($n); //3 or to a specified number of decimal places
$n = 3.142857;
$n = round ($n, 3); //3.143
$m = 23000;
$m = number_format($m); //23,000
▪ NUMBERS: Arithmetic Operators:
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
++ Increment
-- Decrement
▪ CONSTANTS: Constants are a specific data type in PHP which unlike
variables, retain their initial value throughout the course of a script.
UNIVERSIDAD DE MANILA 7
College of Computing Studies
Information Technology Department
SY 2025-2026
ITE 216 – Applications Devt and Emerging Technologies
Prepared by: Arlene Mae C. Valderama
The value of the constant cannot be changed once has it been set.
To create a constant, use the define()function instead of the
assignment operator for variables.
▪ ESCAPE CHARACTERS:
Code Meaning
\" Double quotation mark
\' Single quotation mark
\\ Backslash
\n Newline
\r Carriage return
\t Tab
\$ Dollar sign
▪ Single and Double Quotation Marks: In PHP, values enclosed within
single quotation marks will be treated literally, whereas those within
double quotation marks will be interpolated. Placing variables and
special characters within double quotes will have their represented
values printed, not their literal values.
▪ Third Example: Open text editor and type the code below. Save it as
“[Link]”.
UNIVERSIDAD DE MANILA 8
College of Computing Studies
Information Technology Department
SY 2025-2026
ITE 216 – Applications Devt and Emerging Technologies
Prepared by: Arlene Mae C. Valderama
▪ Output of “[Link]”:
INSTRUCTIONS: Code all sample code snippets in the above lecture
notes using phpDesigner, Sublime Text, or Notepad and save it as .php
files. Summary of the files to be coded and run:
a) [Link]
b) numbers [Link]
c) variables [Link]
INSTRUCTIONS: Answer the machine problem below. Use Notepad++
or any PHP editor. Take a screenshot of the code and the output.
Summary of the files:
a) [Link]
b) [Link] (screenshot of code and
output)
UNIVERSIDAD DE MANILA 9
College of Computing Studies
Information Technology Department
SY 2025-2026
ITE 216 – Applications Devt and Emerging Technologies
Prepared by: Arlene Mae C. Valderama
Write a PHP code that will display the following:
a) complete date and time today.
b) your complete name in all capital letters (using strtoupper()
function); and do the FF.:
▪ Display the Area, Circumference, and Diameter of a circle if the
radius is 823.
▪ Display the Area of a triangle if the base is 100 and the height is
120.
▪ Display the value in degrees Celsius if the degree in Fahrenheit is
76.
▪ Display the value of 1500 pesos in dollars if the conversion factor
is $1 = P58.95
▪ Use the following:
a) Celsius = 5/9 * (Fahrenheit – 32)
b) Diameter = 2 * Radius
c) Circumference = 2 * Pi * Radius
d) Area (circle)= Pi * Radius * Radius
e) Area (triangle) = ½ * Base * Height
Use the screenshot below as guide in coding your PHP file.
UNIVERSIDAD DE MANILA 10
College of Computing Studies
Information Technology Department
SY 2025-2026
ITE 216 – Applications Devt and Emerging Technologies
Prepared by: Arlene Mae C. Valderama
UNIVERSIDAD DE MANILA 11
College of Computing Studies
Information Technology Department
SY 2025-2026