Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
70 views

Module 1 2 Web System

This document provides an introduction to server-side scripting with PHP. It begins with an overview of the differences between client-side and server-side scripting. PHP is introduced as a popular server-side scripting language suited for web development. A brief history of PHP is given, noting it was created in 1994 and has evolved significantly. Key advantages of PHP are listed, including that it is open source, platform independent, simple to learn and code, and can easily connect to databases.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Module 1 2 Web System

This document provides an introduction to server-side scripting with PHP. It begins with an overview of the differences between client-side and server-side scripting. PHP is introduced as a popular server-side scripting language suited for web development. A brief history of PHP is given, noting it was created in 1994 and has evolved significantly. Key advantages of PHP are listed, including that it is open source, platform independent, simple to learn and code, and can easily connect to databases.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 47

Learning Module |Prepared by: MARK JOSHUA V.

QUIAMBAO

1|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

Unit 1| Introduction to Server Side Scripting Language (PHP)


A. LEARNING OBJECTIVES:
1. Defined what is PHP and its practical use in web development.
2. Experienced how to install and setup local webservers.
3. Familiarized oneself on local webservers and PHP files manipulation.
B. PRE-TEST
Direction: Encircle the letter of the correct answer.
1. What is the correct abbreviation for PHP?
a. Programming Hypertext Processor c. Perl Hypertext Preprocessor
b. Page Hypertext Programming d. PHP Hypertext Preprocessor
2. Who is the creator of PHP?
a. Andy Gutsman c. Zeev Suraski
b. Rasmus Lerdorf d. Rob Allen
3. When PHP 7.0 released?
a. 2015 c. 2017
b. 2016 d. 2018
4. It requires browsers to run the scripts on the client machine but does not interact with the server while processing the client-
side scripts.
a. Back end c. Client-Side Scripting Language
b. Server Side Scripting Language d. Hypertext Mark-up Language
5. Which of the following is NOT an example of a server-side scripting language?
a. PHP c. JavaScript
b. ASP.net d. Perl
6. Which of the following is not included in the top 10 of PHP advantages?
a. Simple and Easy c. Fast
b. Security d. Case Sensitive
7. Which of the following is NOT an application of PHP?
a. eCommerce c. Desktop Application
b. Data representation d. Game Development
8. Which of the following server is intended only for OS X?
a. WAMP c. LAMP
b. XAMPP d. MAMP
9. Which of the following is not really needed when running PHP?
a. Database c. Interpreter
b. Web Server d. Web Browser

2|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

10. Which of the following delimiters is recommended by PHP group to use?


a. Standard PHP script delimiters
b. The <script> element
c. Short PHP script delimiters
d. ASP-style script delimiters

C. CONTENT

1.1 Server-side Scripting Language and PHP


What is the difference between client-side and server-side scripting
language?
The scripts can be written in two forms, at the server end (back end)
or the client end (server end). The main difference between server-
side scripting and client-side scripting is that the server-side scripting
involves server for its processing. On the other hand, client-side
scripting requires browsers to run the scripts on the client machine
but does not interact with the server while processing the client-side
scripts. Figure 1.1 Difference between Client-side scripting
and server side scripting language.
The popular server-side scripting language.
The most popular server-side scripting languages and frameworks include PHP, ASP.NET, Node.js, Java, Ruby, Perl and Python.
These scripts run on a web server and respond to client requests via HTTP to deliver dynamic and customized content to the user.
Server-side scripting is required to access or store persistent data like user profile information. Whether that involves pulling data from
a file server, database or mail server, it can all be done with a server-side scripting language like PHP. In this lecture, we will focus on
PHP and its framework.
What is PHP?
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open <!DOCTYPE html>
<html>
source general-purpose scripting language that is especially suited for web <head>
development and can be embedded into HTML. PHP is specifically designed to <title>Example</title>
</head>
fill the gap between static HTML pages fully dynamic pages, such as those <body>
generated through CGI code. <?php
echo "Hi, I'm a PHP script!";
Instead of lots of commands to output HTML (as seen in C or Perl), PHP pages ?>
contain HTML with embedded code that does "something" (in this case, output </body>
"Hi, I'm a PHP script!"). The PHP code is enclosed in special start and end </html>

processing instructions <?PHP and ?> that allow you to jump into and out of
"PHP mode." Figure 1.2 Sample PHP Script

The best things in using PHP are that it is extremely simple for a newcomer, but offers many advanced features for a professional
programmer.
3|Web System and Technologies 2
Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

Brief History of PHP

4|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

Through the years, PHP is the premium choice of developers for developing web applications. Thanks to Rasmus Lerdorf, who back in
1994, conceived the idea of PHP. Working through it, he later made its first-ever version public in 1995 known as PHP/FI. At that time,
it was just a simple PERL/CGI script toolset written in C language. The language evolved quickly after the release of PHP3 in 1998,
which included several advanced features – most importantly – the introduction of the Zend engine. Today, PHP has found its usage in

5|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

many leading organizations for handling their online portfolio. These big guns include Facebook, Wikipedia, Yahoo, WordPress and
others, while the numbers are still growing.

What are the advantages of using PHP?


Figure 1.3 The brief look on PHP versions history, as how it emerged as one of the world’s most used
server-side scripting language through the years.
6|Web System and Technologies 2
Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

PHP has a lot of advantages and some are described above. It has disadvantages as well but it is still better than other programming
languages. It is being widely used the programming language and many people are using this programming language for creating the
different types of a web-based application. It is used because of its features and open source. It does not cost and able to develop the
customized application integrated with other programming languages as well.
Following are the top 10 advantages of PHP which are as follows:
1. Open Source
PHP is open-source and free of cost, which helps developers to install it quickly and readily available for use. There are a lot of PHP
frameworks and developer can choose any of the frameworks to work. All the features and tools will be provided to the developer for
that framework easily. As it is open-source, it makes the system ready with PHP in quick time and makes the web development faster
with the help of providing the tools and other features easily.
2. Platform Independent
PHP is mainly supported by all the operating systems like Windows, UNIX, Linux, etc. The PHP based developed web applications can
be easily run on any platform. It can be integrated with other programming language and database easily and there is no requirement
of re-development. It helps in saving a lot of effort and cost.
3. Simple and Easy
This advantage of PHP is simple and easy to learn and code. It is mainly organized code and clean, which helps the new developers
also. The command functions of PHP can easily learn and understood. The one who knows any programming language can easily
work on PHP. It is simple to learn, as its learning curve is not large. The syntax is simple and flexible to use.
4. Database
PHP is easily connected with the database and make the connection securely with databases. It has a built-in module that is used to
connect to the database easily. There are many web applications, which require strong programming language with a good database
management system. PHP and its database connection solve the purpose for the development of web applications. It reduces the time
to connect to a database management system as well. Multiple databases can be integrated with PHP.
5. Fast
PHP is known as the fastest Programming language as compared to another. PHP applications can be easily loaded over the slow
Internet and data speed. Other applications take a lot of time to connect the database and fetch the data after executing certain queries
to the database. PHP does not face this problem and it loads the website very easily and fast. The fast speed of PHP provides the
developer with an edge to develop the web applications in PHP programming language.
6. Maintenance
PHP framework is mainly used to make the web application development easier and maintain the code automatically. The model view
controller architecture in PHP framework helps the code to be easily maintained and used. The MVC architecture helps the separation
of a file for different module separately.
7. Support
This advantage of PHP has great online support and community, which helps the new developers to help in writing the code and
developing the web applications. The documentation provided at the official site helps in using the different features of PHP and its
framework. The latest updates are released timely by the PHP to make it better for the developer to develop the web-based
applications.

7|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

8. Testing
PHP based web applications can be easily tested. PHP unit uses to perform the unit testing quickly and easily. It also helps the
programmers to write test cases and perform the testing smoothly. For PHP based web applications, the developers do not need to
write the additional code. PHP frameworks help in automating the different tasks.
9. Security
PHP frameworks built-in feature and tools make it easier to protect the web applications from the outer attacks and security threats.
The security threats can be like SQL injection, data tampering, and forgery etc. To protect from these security threats, developers used
PHP frameworks for developing web applications.
10. Stable
PHP is also stable as compared to other programming languages. It has been in existence for a long time. The developers have
worked on PHP to make it easy for the programmers to work on developing the PHP web-based applications. They have fixed the
issues and bugs over the period for the different version of PHP and make it very stable.
What are the applications of PHP?
There are wide applications of PHP in several digital platforms. Now we are going to provide you with some of the important
applications of PHP programming language in different fields with their brief information.
1. Web Pages and Web-Based Applications:
Any web page or web application developed in the current ecosystem needs to offer a high degree of customization, provide a highly
interactive user interface, be capable of performing online transactions and integrate with database systems. Through its three-tiered
architecture which works on browser, server and database system linearly, PHP offers a reliable solution to achieve these features. As
a consequence, PHP is used by over 82% of websites for server-side programming; over 244 million websites are built using PHP.
Further, web-based enterprise applications and a multitude of Facebook apps are also scripted in PHP.
2. Web Content Management Systems:
PHP offers support to numerous databases including MySQL, Oracle and MS Access and is capable of interacting with other services
using protocols such as IMAP, LDAP, POP3, NNTP, SNMP, HTTP and COM . As a result, PHP has been used for creating popular
web Content Management Systems (CMS), including WordPress and its plugins, user-facing portion of Facebook, Joomla, Drupal,
Moodle, Silverstripe, MediaWiki, Digg and others.
3. eCommerce Applications:
From small businesses to large enterprises, selling to online shoppers is now an indispensable requirement. Through use of
frameworks like CodeIgniter and CakePHP, PHP allows creation of eCommerce applications in a swift and simple manner. Many of the
highly used eCommerce platforms, such as OpenCart, Magento, PrestaShop, Zen Cart, AgoraCart and Ubercart, have all been created
on PHP.
4. GUI-Based Applications:
While PHP is largely used as a scripting language for web-based applications, it is also possible to employ it for creating desktop
graphical user interface (GUI) based applications. Tools like PHP-GTK 2, DevelStudio and ZZEE PHP GUI, allow scripting in PHP,
compiling it into .exe capable of running standalone.
5. Create Flash:

8|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

An open source library, such as Ming, helps to create .SWF format movies which include most of the features of Flash – gradients,
bitmaps (pngs and jpeg), morphs, shapes, text, button, actions and animations. Further, Flash elements like login-form and email form
can be easily created and incorporated into dynamic web pages using PHP.
6. Image Processing and Graphic Design:
Apart from managing text content, PHP can also be used to manipulate images. Integration of various image processing libraries, such
as GD library, Imagine and ImageMagick, in PHP applications allows rotating, cropping, resizing, creating thumbnail pictures, adding
watermarks and generating output images in multiple formats including jpeg, gif, wbmp, xpm and png. This feature is an essential
requirement for building robust websites and web applications.
7. Data Representation:
Through use of tools like Image_Graph, PHP can be used to create a variety of graphs, charts, scatter-dot plots and other means of
graphical representations. This feature finds application across client-side desktop applications, eCommerce websites and other
applications where data needs to be presented in a concise and graphical manner.
8. Creating PDF Files:
Further, by use of a library called PDFLib, PHP can be used to generate PDF files. This can facilitate the creation of an online invoicing
system where an HTML-driven invoice is created in PDF format.
1.2 Introducing XAMPP and WAMPP
What you need to run PHP?
To run PHP code, you need the following three software on your local machine:
1. Web Server. A web server is a computer that runs websites. It's a computer program that distributes web pages as they are
requisitioned. The main job of a web server is to display the website content. The most commonly used web server is Apache,
an open-source and free web server software that powers around 40% of websites around the world. The official name is
Apache HTTP Server, and it’s maintained and developed by the Apache Software Foundation.
2. PHP (Interpreter). PHP is an interpreted language. This means that you will write code statements (lines of code) and when a
page is requested, the PHP interpreter will load your PHP code, parse it and then execute it.
3. Database Software (optional). Database software is designed to create databases and to store, manage, change, search, and
extract the information contained within them. A comprehensive database software program is sometimes called a database
management system. MySQL is the most popular database system used with PHP.
You can separately install Web Server, PHP Interpreter, and databases, but to make work easier, developers have made all in one
setup package that will automatically install and set up PHP environment on your Windows, Linux or MAC machines. There following
are the four common web server solution package used:

 WAMP (Windows, Apache, MySQL, PHP)


 LAMP (Linux, Apache, MySQL, PHP)
 MAMP (MAC, Apache, MySQL, PHP)
 XAMPP (Windows/Linux/MAC, Apache, MySQL, PHP)
In this lecture we will discuss how to setup and install WAMP since most of us are using Window OS and XAMPP because it is cross-
platform.
WAMP Server Installation

9|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

WampServer is a Windows web development


environment. It allows you to create web applications
with Apache2, PHP and a MySQL database.
Alongside, PhpMyAdmin allows you to manage easily
your databases.
Here are the simple steps of to install the WAMP
server.
1. Download the App. If you don’t have yet
installer of WAMP, you can download it to
their official website
https://www.wampserver.com/en/ .
But before downloading, it is important to
know what kind of processor architecture Figure 1.4 Official Website where you can download the latest
your machine has. If it is 64bit then choose version of WAMP.
the installer for 64bits, else choose 32bits if
your machine is 32bits.

2. Initiate WAMP Server Install Process. Soon


after you click on the downloaded file, you
will be asked to choose your preferred
language and click the “Ok” button. As I’m
choosing English as shown in Figure 1.5.

Figure 1.5 Official Website where you can download the latest
version of WAMP.

On Figure 1.6, you will see is about the license


agreement. Click on the “I accept the agreement”
radio button and then the “Next” button to continue
with the installation shown on the following figure.

10|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

Figure 1.7 will inform you about the required


components that have to be present in your computer
system for the proper functioning of the WAMP
Server. The main purpose of this step is to check for the
suitable version of Microsoft VC++ re-distributable
package. Click on the ‘Next’ to continue.

Figure 1.7 Information

3. Select Location/Destination to Install WAMP


Here, you need to select the location to install the
WAMP on your computer. However, you can
accept the default location and move ahead. To
continue with the installation hit the ‘Next’ button.

11|Web System and Technologies 2 Figure 1.8 Installation Location


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

4. Select Start Menu Folder to Install WAMP


Now, you need to select the folder where you wish to
create the program’s shortcut. You can select any
folder of your choice or you can continue with the
default option. You can easily access this folder
from the Windows start button. Choose the folder
and click ‘Next’ to continue.

Figure 1.8 Select Start menu Folder

5. Ready to Install WAMP


Finally, you would see a ready to install wizard with a
ready setup to begin the installation. Just hit the ‘Install’
button to begin the installation procedure.

Now, just be patient as the WAMP Server is extracting


files to your selected location. Let the process complete.
Once the status bar is turned fully green, an information

Figure 1.9 Select Start menu Folder

screen will appear like Figure 1.10. Click ‘Next’ to


continue.

12|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

6.

Figure 1.10 Installation Progress Bar WAMP 1.11


Figure Installation Complete
Additional information how WAMP
The installation is almost done now simply click ‘Finish’
to exit the setup. That’s all. You are ready with the WAMP server now.

Figure 1.12 Installation Finished

How to access WAMP?


Here are some easy steps to access your install WAMP server.

1. Click the WAMP icon to start WAMP.


You can find the WAMP icon in
Windows Start menu or desktop. You
will see a few Command Prompt
windows appear and then disappear.
When WAMP is running, you can find
the WAMP logo icon in the Windows
Taskbar in the lower-right corner. If
the WAMP icon is green, all services
are running. If the WAMP icon is
yellow, some services are running. If
the WAMP icon is red, no services
are running.

Figure 1.13 WAMP icon on Desktop

13|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

2. Click the WAMP icon in the taskbar.


This opens the WAMP menu, then
www directory to open your local site
folder. This is the folder labeled
"www" in the WAMP installation
folder. Save all your local website
builds in this folder. You can create a
new subfolder for each website build
you want to make and save all your
HTML, CSS, PHP, and other website
files in that folder (Figure 1.14).

Figure 1.14 WAMP icon

3. Login to phpMyAdmin. You can use


phpMyAdmin to create new
databases and manage them. Use
the following steps to log in to
phpMyAdmin: Click the WAMP icon
in the taskbar. Click phpMyAdmin.
Use the drop-down menu next to
"Server Choice" to select MariaDB or
MySQL. Enter "root" as the default
username. Leave the password field
blank. Click Go.

Figure 1.15 Accessing phpMyAdmin Page

XAMPP Server Installation


XAMPP is an easy to install Apache distribution containing MariaDB, PHP, and Perl available in multiple operating system like
Windows, Linux and OS X (Mac). In this lecture we will only discuss the installation of XAMPP in Windows, but at the last part of this,
there are YouTube link for Linux and OS X installation.
Here are the easy steps of installation.

14|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

1. Download the Installer. If you don’t have yet the latest


installer of XAMPP, you can download it in
https://www.apachefriends.org/download.html. Click XAMPP
for Windows. It's a grey button near the bottom of the page.

Figure 1.16 XAMPP Official Website

2. Double-click the downloaded file. This file should be


named something like xampp-win32-7.2.4-0-VC15-
installer, and you'll find it in the default downloads location
(e.g., the "Downloads" folder or the desktop).

Figure 1.17 XAMPP Installer

3. Click Yes when prompted. This will open the XAMPP setup window. You may have to click OK on a warning if you have User
Account Control (UAC) activated on your computer. The
click Next.

Figure 1.18 XAMPP Initial Installation Window

4. Select aspects of XAMPP to install. Review the list of


XAMPP attributes on the left side of the window; if you
see an attribute that you don't want to install as part of
XAMPP, uncheck its box. By default, all attributes are
included in your XAMPP installation.

15|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

Figure 1.19 XAMPP Initial Installation Window

How to configure your XAMPP?


Here are the few steps to configure your XAMPP server.
1. Double-click on the newly created XAMPP icon. It has an orange icon that resembles an "X". This will display the XAMPP
Control Panel.

Figure 1.20 Locating XAMPP Control Panel

2. Click Start buttons next to Apache and MySQL. This starts the personal web service or Apache and MySQL.

16|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

Figure 1.21 Starting Apache and MySQL

3. Click Admin next to Apache. If everything is working properly, you should see the XAMPP Dashboard. You can click one of
the icons at the bottom of the screen to see a list of additional modules you can install and use with XAMPP. These include
WordPress, Drupal, Joomla, Mautic, OpenCart, OwnCloud, phpList, phpBB, and more. Alternatively, you can go to
http://localhost/ in a web browser.

Figure 1.22 Apache Admin

4. Click Admin next to "MySQL". This opens the phpMyAdmin dashboard. Here you can configure your PHP databases.

17|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

Figure 1.23 Opening phpMyAdmin dashboard

If in case your Operating System is not Windows I provided some Youtube link below.
https://www.youtube.com/watch?v=_hmNWQtl1bo
https://www.youtube.com/watch?v=EK_AUTzV7OI

1.3 Working with Basic PHP file


How to create PHP file?
It is easy to create PHP file, it is just the same way you create HTML file. If you are using Notepad++, just click File>Save As and
choose PHP Hypertext Preprocessor file like what shown in the Figure 1.24. It is suggested that before start writing PHP script, you
should save it to identify what kind of codes you are writing. The default file extension for PHP files is ".php". A PHP file normally
contains HTML tags, and some PHP scripting code.

18|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

Figure 1.24 Saving PHP file Creating


PHP code
blocks
PHP is an embedded language because code is embedded within a Web page (HTML or XHTML document) just like JavaScript. You
write PHP scripts within code declaration blocks, which are separate sections on a Web page that are interpreted by the scripting
engine. You can include as many code declaration blocks as you want within a document. There are four types of code declaration
blocks that you can use to write PHP:

 Standard PHP script delimiters


 The <script> element
 Short PHP script delimiters
 ASP-style script delimiters
As you can see most of the code declaration blocks has the word ‘delimiter’. A delimiter is a character or sequence of characters used
to mark the beginning and end of a code segment.
What is the standard PHP script delimiters?
The standard method of writing PHP code declaration blocks is to use the <? <!DOCTYPE html>
php as opening and ?> for closing script delimiters. When the scripting engine <html>
encounters the <?php and ?> script delimiters, it process any code between the
<body>
delimiters as PHP. The individual lines of codes that make up a PHP script are
called statements. Figure 1.25 shows an script that contains single statement
that writes the text “Hello World!” to a web browsers windows using an echo
<h1>My first PHP page</h1>
statement.
<?php
Even though PHP Group officially recommends to use standard PHP script echo "Hello World!";
delimiters to write PHP, some Web developers prefer the other types of codes ?>
19|Web System and Technologies 2
</body>
</html>
Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

declaration blocks, so you must be able to recognize the other delimiters when you them.
What is the syntax of the other delimiters?
Figure 1.25 Using ‘echo’ statement
The <script> element
When the script element is used with PHP, you must assign a value of “php” to the
<script language="php">
language attribute of the <script> like what shown in Figure 1.26. Like the standard
echo "Hello World!"; PHP script delimiters, the <script> element is always available on any Web server
</script> that support PHP. Unfortunately, the <script element’s language attribute
deprecated in XHTML, as a result you cannot validate documents that include PHP
Figure 1.26 Sample code using <script> <script> elements.
element
Short PHP Script Delimiters
A simplified method of writing PHP code declaration blocks is to use the short
<?
script like what shown in Figure 1.27. Although it is simple and short, the major
echo "Hello World!"; drawback of this delimiter is it is not available in all webserver unlike the standard
?> and <script>. That’s why the PHP Group discourages the use of short delimiters,
Figure 1.27 Sample Short PHP script especially when it redistributed and used by others.
ASP-Style Script Delimiters
The ASP-style delimiters is similar to short PHP, the only difference is the
<% question mark was replaced by percent symbol like what shown in Figure 1.28.
echo "Hello World!"; ASP-style script can also ne enabled or disabled in the php.ini configuration file,
%> so you should not use them unless you are sure they are enabled on any Web
Figure 1.28 Sample ASP-style script servers on which PHP script will run.

Is PHP case sensitive?


In PHP, variable names are case-sensitive but function names are not case sensitive. If you defined variable in lowercase, then you
need to use it in lowercase everywhere in the program. If we define a variable $name = "James"; then we must need to use $name.
$NAME will not work. If you defined function name in lowercase, but calling them in uppercase it will work. For example, If we define
function sum() {} then calling SUM() will also work.
Function names are not case-sensitive, though it is good to call functions in the same case as they appear in their declaration for
consistency.

D. Learning Activity
Activity No. 1
Direction: Make your own tutorial video of WAMP or XAMPP installation. You will be graded based on the rubrics provided.

E. Assessment

Direction: Encircle the letter of the correct answer.

1. Who is the creator of PHP?


a. Andy Gutsman b. Rasmus Lerdorf

20|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

c. Zeev Suraski d. Rob Allen


2. What is the correct abbreviation for PHP?
a. Programming Hypertext Processor c. Perl Hypertext Preprocessor
b. Page Hypertext Programming d. PHP Hypertext Preprocessor
3. When PHP 7.0 released?
a. 2015 c. 2017
b. 2016 d. 2018
4. It requires browsers to run the scripts on the client machine but does not interact with the server while processing the client-
side scripts.
a. Back end c. Client-Side Scripting Language
b. Server Side Scripting Language d. Hypertext Mark-up Language
5. Which of the following is NOT an example of server-side scripting language?
a. PHP c. JavaScript
b. ASP.net d. Perl
6. Which of the following is not included in the top 10 of PHP advantages?
a. Simple and Easy c. Fast
b. Security d. Case Sensitive
7. Which of the following is NOT an application of PHP?
a. eCommerce c. Desktop Application
b. Data representation d. Game Development
8. Which of the following server is intended only for OS X?
a. WAMP c. LAMP
b. XAMPP d. MAMP
9. Which of the following is not really needed when running PHP?
a. Database c. Interpreter
b. Web Server d. Web Browser
10. Which of the following delimiters is recommended by PHP group to use?
a. Standard PHP script delimiters c. Short PHP script delimiters
b. The <script> element d. ASP-style script delimiters

REFERENCES
https://techdifferences.com/difference-between-server-side-scripting-and-client-side-scripting.html
https://www.fasthosts.co.uk/blog/client-side-vs-server-side-scripting/
https://www.php.net/manual/en/intro-whatis.php
https://www.educba.com/advantages-of-php/
https://www.cloudways.com/blog/php-version-history/
https://www.invensis.net/blog/applications-php-programming-language/

21|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

https://www.w3trainingschool.com/applications-php-programming-language
https://economictimes.indiatimes.com/definition/web-server
https://www.w3schools.in/php/install/
https://www.hostinger.ph/tutorials/what-is-apache
https://stillat.com/blog/2014/04/02/how-does-php-work-with-the-web-server-and-browser
https://www.quickbase.com/articles/database-software-basics
https://www.w3schools.com/php/php_mysql_intro.asp
https://blog.templatetoaster.com/how-to-install-wamp/
https://www.wikihow.com/Install-WAMP
https://www.w3schools.com/php/php_syntax.asp
https://www.apachefriends.org/download.html
https://www.wikihow.com/Install-XAMPP-for-Windows
https://www.wikihow.com/Set-up-a-Personal-Web-Server-with-XAMPP
https://tutorialsclass.com/faq/is-php-a-case-sensitive-language/
Gosselin, D., Kokoska, D., & Easterbrooks, R., 2011, “PHP Programming with MySQL”. Cengage Learning

22|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

Activity Rubrics

Developing Accomplished Distinguished


1- 5 6 - 10 11 - 15
Content & Organization Portions may be poorly Fairly well documented and The program shows a
Is your project organized and documented and/or organized. The format is easy continuous progression of
documented? organized. Hard to follow to follow. Good explanation ideas and tells a complete,
the progressions of the story. shows good effort. easily followed story. Well
Explanation shows some documented and organized.
effort. Excellent, well thought out
explanation shows superior
effort.
Usefulness – The project demonstrated Project is focused and Project is focused and very
Does your video stay the development of informative; promotes the use of informative; promotes the use
focused on an informative computer technology; has computer technology to create of computer technology to
topic? Does it promote the problems staying focused on the video to deliver information. create the video and makes
use of technology to inform the topic. others want to use the same
the audience about the type of format in delivering
topic? information to an audience.
Creativity & Elements of Minimal use of design Good use of graphics and/or Excellent sense of design.
Design – Is your video elements. No transitions. other design elements. Some Effective camera techniques
interesting? Did your choice Sound is lacking or transitions are inappropriately used for the video and
of elements such as film inappropriate or scratchy. placed. Sound quality is OK. pictures. Video and pictures
clips, pictures, backgrounds, Some pictures or video clips Video clips or pictures are clear are I focus and of good
and transitions enhance the may be out of focus or and in focus. quality. Smooth transitions
project? “shaky”. are appropriate and aid in the
delivery of the presentation.
Oral Presentations Skills – Some difficulty Fairly fluid delivery. Well-rehearsed. Voice, eye
Did you respond to the communicating ideas. Poor Communicates ideas with contact and pacing hold
questions by the students voice projections; some eye proper voice projection; perhaps interest and attention of the
and instructor with ease? contact; no introduction; one mispronounced work; made audience; introduced self and
mispronounced a few words; eye contact; introduced self and project. Responded easily to
long pauses; somewhat project. Respond to questions. questions.
confused.
Source: https://www.dit.ie/media/teachertraining/case0023-digitalmultimedia/Evaluation%20Rubric%20for%20Video
%20Production.docx

23|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

UNIT 2| Variables, Operators, Strings and String Functions


__________________________________________________________________________________________________________
A. Learning Outcome:
At the end of the topic, the students must have:
 gained knowledge on the different operators in PHP
 familiarized oneself on the different string functions that will be beneficial in creating a website.
 practiced to use the different data types and determined their use
B. Pre-Test
1. Which of the variables is float?
a. $qty = “1.01”; c. $qty = ‘1.01’;
b. $qty = 1; d. $qty = 1.001;
2. Which of the following is correct when declaring a constant?
a. Define {‘Price’, 10}; c. define (price, 100);
b. define (‘Price’); d. define (‘price’, 100);
3. Which of the following variables is visible everywhere within the script?
a. Constant c. Built-in superglobal variables
b. Global variables d. Variables declared inside the function
4. Which of the following is an string operator?
a. Addition (+) c. Less than (<)
b. Identical (===) d. Concatenation (.
5. Which of the following is a logical operator?
a. && c. <>
b. != d. %=
6. Which of the following has an equivalent of $a= $a + $b?
a. $a =+ $b c. $b += $a
b. $a += $b d. $b =+ $a
7. Which of the following is NOT TRUE about PHP variables?
a. All variables in PHP are denoted with a leading dollar sign ($).
b. PHP does a good job of automatically converting types from one to another when necessary.
c. The value of a variable is the value of its most recent assignment.
d. PHP variable has only 5 datatypes
8. In PHP operators, which of the following is an equal operator?
a. = c. ===
b. == d. !=
9. A variable that has a value is set once and then cannot be changed elsewhere in the script.
a. Variable variable c. Resource
b. Constant d. Arrays
10. It is an operator that are used with numeric values to write a value to a variable.
a. Assignment Operator c. Conditional Operator
b. Arithmetic Operator d. Logic Operator
C. Content
24|Web System and Technologies 2
Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

What is PHP Variables?


The main way to store information in the middle of a PHP program is by using a variable. Here are the most important things to know
about variables in PHP.
 All variables in PHP are denoted with a leading dollar sign ($).
 The value of a variable is the value of its most recent assignment.
 Variables are assigned with the = operator, with the variable on the left-hand side and the Note:
expression to be evaluated on the right.
 Variables can, but do not need, to be declared before assignment. We will explain only
 Variables in PHP do not have intrinsic types - a variable does not know in advance whether simple data type in this
it will be used to store a number or a string of characters. chapters. Array, Objects
 Variables used before they are assigned have default values. and Resources will be
 PHP does a good job of automatically converting types from one to another when necessary. explained separately.
PHP has a total of eight data types which we use to construct our variables:
 Integers − are whole numbers, without a decimal point, like 4195.

 Doubles (also known as float) − are floating-point numbers, like 3.14159 or 49.1.

 Booleans − have only two possible values either true or false.

Booleans can be used to control the flow of code

 NULL − is a special type that only has one value: NULL.

 Strings − are sequences of characters, like 'PHP supports string operations.

Like an array, a string can be indexed to return its individual characters:

25|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

 Arrays − are named and indexed collections of other values.

Arrays can also associate a key other than an integer index to a value. In PHP, all arrays are associative arrays behind the scenes, but
when we refer to an 'associative array' distinctly, we usually mean one that contains one or more keys that aren't integers.

 Objects − are instances of programmer-defined classes, which can package up both other kinds of values and functions that
are specific to the class.

 Resources − are special variables that hold references to resources external to PHP (such as database connections).
The first five are simple types, and the next two (arrays and objects) are compound - the compound types can package up other
arbitrary values of arbitrary type, whereas the simple types cannot.

To get the type of a variable as a string, use the gettype() function:

Type Strength

PHP is called weakly typed, or dynamically typed language. In most programming languages, variables can hold only one type of data,
and that type must be declared before the variable can be used, as in C. In PHP, the type of a variable is determined by the value
assigned to it.
For example, you have a variable $total you assigned a value of “0”, just what you see below.

$total=0;

The PHP distinguished its datatype as integers since you assigned a whole numeric value which is zero (0). Let say you realized that
the $total might not always whole number so you changed the value as “0.00” like what shown below.

Did you know?


26|Web System and Technologies 2
You can use single quote
when you are declaring
static string, while double
Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

$total=0.00;

PHP will categorized it now as double since it has decimal point. On the other hand, when you want to define a string variable type you
need to have single or double quotation like what shown below.
<?php
$username= ‘cuteako123’; Output:
$user= “My user name is $username”;
cuteako123
echo $username; My user name is cuteako123
echo $user;

?>
This ability to change types transparently on the fly can be extremely useful. Remember PHP "automagically" knows what data type
you put into your variable. It returns the data with the same data type when you retrieve it from the variable.

Type Casting

You can pretend that a variable or value is of a different type by using a type cast. This feature works identically to the way it works in
C. You simply put the temporary type in parentheses in front of the variable you want to cast. For example, you could have declared the
two variables from the preceding section using a cast:

$total 0;
$totalamount = (float) $total;

The second line means "Take the value stored in $total, interpret it as a float, and store it in $totalamount." The $total amount variable
will be of type float. The cast variable does not change types, so $total remains of type integer.
You can also use the built-in function to test and set type, which you will learn about later in this chapter.

Variable Variables

PHP provides one other type of variable: the variable variable. Variable variables enable you to change the name of a variable
dynamically. As you can see, PHP allows a lot of freedom in this area. All languages enable you to change the value of a variable, but
not many allow you to change the variable's type, and even fewer allow you to change the variable's name. A variable variable works
by using the value of one variable as the name of another For example, you could set

$varname = 'total';

You can then use $$varname in place of $total. For example, you can set the value of $total as follows:

$$varname = 5;

This is exactly equivalent to


$total = 5;

This approach might seem somewhat obscure, but we'll revisit its use later. Instead of having to list and use each form variable
separately, you can use a loop and variable to process them all automatically. This will be discuss on for loops later on this module.

Declaring and Using Constants

As you saw previously, you can readily change the value stored in a variable. You can also declare constants. A constant stores a
value just like a variable, but its value is set once and then cannot be changed elsewhere in the script. In the sample application, you
might store the prices for each item on sale as a constant. You can define these constants using the define function:
27|Web System and Technologies 2
Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

define ( 'Pi', 3.1416);


define ( ‘PRICE’, 100);

One important difference between constants and variables is that when you refer to a constant, it does not have a dollar sign in front of
it. If you want to use the value of a constant, use its name only. For example, to use one of the constants just created, you could type
Output:
echo Pi; 3.1416
As well as the constants you define, PHP sets a large number of its own. An easy way to obtain an overview of them is to run the
phpinfo() function:

phpinfo ():

This function provides a list of PHP's predefined variables and constants, among other useful information. We will discuss some of
them as we go along. One other difference between variables and constants is that constants can store only Boolean, integer, float, or
string data. These types are collectively known as scalar values.

Understanding Variable Scope


In PHP, variables can be declared anywhere in the script. The scope of a variable is the part of the script where the variable can be
referenced/used. PHP has three different variable scopes:
 local
 global
 static
Examples:

Variables with Local Scope Variables with Global Scope


<?php <?php
function myTest() { $x = 5; // global scope
$x = 5; // local scope
echo "<p>Variable x inside function function myTest() {
is: $x</p>"; // using x inside this function will
} generate an error
myTest(); echo "<p>Variable x inside function is:
$x</p>";
// using x outside the function will }
generate an error myTest();
echo "<p>Variable x outside function
is: $x</p>"; echo "<p>Variable x outside function is:
?> $x</p>";
?>

There are six basic scope rules in PHP are as follows:


 Built-in superglobal variables are visible everywhere within a script. Note:
 Constants, once declared, are always visible globally; that is, they can be used inside and
outside functions. You can have local
 Global variables declared in a script are visible throughout that script, but not inside variables with the same
functions. name in different functions,
because local variables are
28|Web System and Technologies 2
only recognized by the
function in which they are
declared.
Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

 Variables inside functions that are declared as global refer to the global variables of the same name.
 Variables created inside functions and declared as static are invisible from outside the function but keep their value between
one execution of the function and the next.
 Variables created inside functions are local to the function and cease to exist when the function terminates.

The arrays $_GET and $_POST and some other special variables have their own scope rules. They are known as superglobals or
autoglobals and can be seen everywhere, both inside and outside functions.
The complete list of superglobals is as follows: $GLOBALS-An array of all global variables (Like the global keyword, this allows you to
access global variables inside a function-for example, as
 $_GLOBALS[ 'myvariable'1.)
 $_SERVER-An array of server environment variables
 $_GET-An array of variables passed to the script via the GeT method
 $_POST-An array of variables passed to the script via the PoST method
 $_COOKIE-An array of cookie variables
 $_FILES-An array of variables related to file uploads
 $_ENV-An array of environment variables
 $_REQUEST-An array of all user input including the contents of input including
 $_GET, $_POST, and $_COOKIE (but not including $_FILES since PHP 4.3.0)
 $_SESSION-An array of session variables
We come back to each of these superglobals throughout the module as they become relevant. We cover scope in more detail when we
discuss functions and classes later in this chapter. For the time being, all the variables we use are global by default.

Outputting the Value of a Variable


To build a dynamic and interactive PHP program, it is useful to output variables and their values. The PHP language allows for multiple
methods of value output. This topic covers the standard methods of printing a value in PHP and where these methods can be used.

 echo and print- The echo and print are language constructs, not functions. This means that they don't require parentheses
around the argument like a function does (although one can always add parentheses around almost any PHP expression and
thus echo("test") won't do any harm either). They output the string representation of a variable, constant, or expression. They
can't be used to print arrays or objects.

29|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

When outside of PHP tags, a shorthand notation for echo is available by default, using <?= to begin output and ?> to
end it. For example:

Note that there is no terminating ;. This works because the closing PHP tag acts as the terminator for the single statement. So, it is
conventional to omit the semicolon in this shorthand notation.

Priority of print
Although the print is language construction it has priority like operator. It places between = += -= *= **= /= .= %=
&= and and operators and has left association. Example:

Differences between echo and print


In short, there are two main differences:
 print only takes one parameter, while echo can have multiple parameters.
 print returns a value, so can be used as an expression.

Using Operators
Operators are symbols that you can use to manipulate values and variables by pertorming an operation on them.
30|Web System and Technologies 2
Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

PHP divides the operators in the following groups:


 Arithmetic operators
 Assignment operators
 Comparison operators
 Increment/Decrement operators
 Logical operators
 String operators
 Array operators
 Conditional assignment operators

Arithmetic Operators-The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as
addition, subtraction, multiplication etc.
Operator Name Example Result

+ Addition $x + $y Sum of $x and $y

- Subtraction $x - $y Difference of $x and $y

* Multiplication $x * $y Product of $x and $y

/ Division $x / $y Quotient of $x and $y

% Modulus $x % $y Remainder of $x divided by $y

** Exponentiation $x ** $y Result of raising $x to the $y'th power

Assignment Operators- The PHP assignment operators are used with numeric values to write a value to a variable. The basic
assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.
Assignment Same as... Description

x=y x=y The left operand gets set to the value of the expression on the right

x += y x=x+y Addition

x -= y x=x-y Subtraction

x *= y x=x*y Multiplication

x /= y x=x/y Division

x %= y x=x%y Modulus

Comparison Operators-The PHP comparison operators are used to compare two values (number or string):
Operator Name Example Result

== Equal $x == $y Returns true if $x is equal to $y

31|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

=== Identical $x === $y Returns true if $x is equal to $y, and they are of the same type

!= Not equal $x != $y Returns true if $x is not equal to $y

<> Not equal $x <> $y Returns true if $x is not equal to $y

!== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the same type

> Greater than $x > $y Returns true if $x is greater than $y

< Less than $x < $y Returns true if $x is less than $y

>= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y

<= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y

<=> Spaceship $x <=> $y Returns an integer less than, equal to, or greater than zero, depending
on if $x is less than, equal to, or greater than $y. Introduced in PHP 7.

Increment / Decrement Operators-The PHP increment operators are used to increment a variable's value while decrement operators
are used to decrement a variable's value.
Operator Name Description

++$x Pre-increment Increments $x by one, then returns $x

$x++ Post-increment Returns $x, then increments $x by one

--$x Pre-decrement Decrements $x by one, then returns $x

$x-- Post-decrement Returns $x, then decrements $x by one

PHP Logical Operators


The PHP logical operators are used to combine conditional statements.
Operator Name Example Result

and And $x and $y True if both $x and $y are true

or Or $x or $y True if either $x or $y is true

xor Xor $x xor $y True if either $x or $y is true, but not


both

&& And $x && $y True if both $x and $y are true

|| Or $x || $y True if either $x or $y is true

! Not !$x True if $x is not true

PHP String Operators


PHP has two operators that are specially designed for strings.
32|Web System and Technologies 2
Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

Operator Name Example Result

. Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2

.= Concatenation assignment $txt1 .= $txt2 Appends $txt2 to $txt1

PHP Array Operators


The PHP array operators are used to compare arrays.
Operator Name Example Result

+ Union $x + $y Union of $x and $y

== Equality $x == $y Returns true if $x and $y have the same key/value pairs

=== Identity $x === $y Returns true if $x and $y have the same key/value pairs in the same order
and of the same types

!= Inequality $x != $y Returns true if $x is not equal to $y

<> Inequality $x <> $y Returns true if $x is not equal to $y

!== Non-identity $x !== $y Returns true if $x is not identical to $y

Conditional Assignment Operators-The PHP conditional assignment operators are used to set a value depending on conditions:
Operator Name Example Result

?: Ternary $x = expr1 ? expr2 : expr3 Returns the value of $x.


The value of $x is expr2 if expr1 = TRUE.
The value of $x is expr3 if expr1 = FALSE

?? Null coalescing $x = expr1 ?? expr2 Returns the value of $x.


The value of $x is expr1 if expr1 exists, and is not NULL.
If expr1 does not exist, or is NULL, the value of $x
is expr2. Introduced in PHP 7

PHP String Formatting and String Functions

PHP string is a sequence of characters i.e., used to store and manipulate text. PHP supports only 256-character set and so that it does
not offer native Unicode support. There are 4 ways to specify a string literal in PHP.
 Single Quoted-We can create a string in PHP by enclosing the text in a single-quote. It is the easiest way to specify string in
PHP.
For Example

For specifying a literal single quote, escape it with a backslash (\) and to specify a literal backslash (\) use double backslash (\\). All the
other instances with backslash such as \r or \n, will be output same as they specified instead of having any special meaning.

33|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

We can store multiple line text, special characters, and escape sequences in a single-quoted PHP string.

34|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

 Double Quoted-In PHP, we can specify string through enclosing text within double quote also. But escape sequences and
variables will be interpreted using double quote PHP strings.

Now, you can't use double quote directly inside double quoted string.

We can store multiple line text, special characters and escape sequences in a double quoted PHP string.

35|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

In double quoted strings, variable will be interpreted.

 Heredoc-Heredoc syntax (<<<) is the third way to delimit strings. In Heredoc syntax, an identifier is provided after this heredoc
<<< operator, and immediately a new line is started to write any text. To close the quotation, the string follows itself and then
again that same identifier is provided. That closing identifier must begin from the new line without any whitespace or tab.

Naming Rules-The identifier should follow the naming rule that it must contain only alphanumeric characters and
underscores, and must start with an underscore or a non-digit character.

For Example

Valid Example

Invalid Example

We cannot use any whitespace or tab before and after the identifier and semicolon, which means identifier must not be indented. The
identifier must begin from the new line.

36|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

This code will generate an error.

Heredoc is similar to the double-quoted string, without the double quote, means that quote in a heredoc are not required. It can also
print the variable's value.

Example

We can add multiple lines of text here between heredoc syntax.

37|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

Below are the example with class and their variable

38|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

 Newdoc- Newdoc is similar to the heredoc, but in newdoc parsing is not done. It is also identified with three less than symbols
<<< followed by an identifier. But here identifier is enclosed in single-quote, e.g. <<<'EXP'. Newdoc follows the same rule as
heredocs.

The difference between newdoc and heredoc is that - Newdoc is a single-quoted string whereas heredoc is a double-quoted string.

Go to view page source and see the source of the program

Example

39|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

Example below shows that newdoc does not print the variable's value

Output:

The output of the above program will be like:

Invalid Example

We cannot use any whitespace or tab before and after the identifier and semicolon, means identifier must not be indented. The
identifier must begin from the new line. It is also invalid in newdoc same as heredoc.

40|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

This code will generate an error.

PHP String Functions

The PHP string functions are part of the PHP core. No installation is required to use these functions.
Function Description

addcslashes() Returns a string with backslashes in front of the specified characters

addslashes() Returns a string with backslashes in front of predefined characters

bin2hex() Converts a string of ASCII characters to hexadecimal values

chop() Removes whitespace or other characters from the right end of a string

chr() Returns a character from a specified ASCII value

chunk_split() Splits a string into a series of smaller parts

convert_cyr_string() Converts a string from one Cyrillic character-set to another

convert_uudecode() Decodes a uuencoded string

convert_uuencode() Encodes a string using the uuencode algorithm

count_chars() Returns information about characters used in a string

crc32() Calculates a 32-bit CRC for a string

crypt() One-way string hashing

echo() Outputs one or more strings

explode() Breaks a string into an array

fprintf() Writes a formatted string to a specified output stream

get_html_translation_table() Returns the translation table used by htmlspecialchars() and htmlentities()

hebrev() Converts Hebrew text to visual text

hebrevc() Converts Hebrew text to visual text and new lines (\n) into <br>

hex2bin() Converts a string of hexadecimal values to ASCII characters

html_entity_decode() Converts HTML entities to characters

41|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

htmlentities() Converts characters to HTML entities

htmlspecialchars_decode() Converts some predefined HTML entities to characters

htmlspecialchars() Converts some predefined characters to HTML entities

implode() Returns a string from the elements of an array

join() Alias of implode()

lcfirst() Converts the first character of a string to lowercase

levenshtein() Returns the Levenshtein distance between two strings

localeconv() Returns locale numeric and monetary formatting information

ltrim() Removes whitespace or other characters from the left side of a string

md5() Calculates the MD5 hash of a string

md5_file() Calculates the MD5 hash of a file

metaphone() Calculates the metaphone key of a string

money_format() Returns a string formatted as a currency string

nl_langinfo() Returns specific local information

nl2br() Inserts HTML line breaks in front of each newline in a string

number_format() Formats a number with grouped thousands

ord() Returns the ASCII value of the first character of a string

parse_str() Parses a query string into variables

print() Outputs one or more strings

printf() Outputs a formatted string

quoted_printable_decode() Converts a quoted-printable string to an 8-bit string

quoted_printable_encode() Converts an 8-bit string to a quoted printable string

quotemeta() Quotes meta characters

rtrim() Removes whitespace or other characters from the right side of a string

setlocale() Sets locale information

sha1() Calculates the SHA-1 hash of a string

42|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

sha1_file() Calculates the SHA-1 hash of a file

similar_text() Calculates the similarity between two strings

soundex() Calculates the soundex key of a string

sprintf() Writes a formatted string to a variable

sscanf() Parses input from a string according to a format

str_getcsv() Parses a CSV string into an array

str_ireplace() Replaces some characters in a string (case-insensitive)

str_pad() Pads a string to a new length

str_repeat() Repeats a string a specified number of times

str_replace() Replaces some characters in a string (case-sensitive)

str_rot13() Performs the ROT13 encoding on a string

str_shuffle() Randomly shuffles all characters in a string

str_split() Splits a string into an array

str_word_count() Count the number of words in a string

strcasecmp() Compares two strings (case-insensitive)

strchr() Finds the first occurrence of a string inside another string (alias of strstr())

strcmp() Compares two strings (case-sensitive)

strcoll() Compares two strings (locale based string comparison)

strcspn() Returns the number of characters found in a string before any part of some specified characters are
found

strip_tags() Strips HTML and PHP tags from a string

stripcslashes() Unquotes a string quoted with addcslashes()

stripslashes() Unquotes a string quoted with addslashes()

stripos() Returns the position of the first occurrence of a string inside another string (case-insensitive)

stristr() Finds the first occurrence of a string inside another string (case-insensitive)

strlen() Returns the length of a string

strnatcasecmp() Compares two strings using a "natural order" algorithm (case-insensitive)

43|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

strnatcmp() Compares two strings using a "natural order" algorithm (case-sensitive)

strncasecmp() String comparison of the first n characters (case-insensitive)

strncmp() String comparison of the first n characters (case-sensitive)

strpbrk() Searches a string for any of a set of characters

strpos() Returns the position of the first occurrence of a string inside another string (case-sensitive)

strrchr() Finds the last occurrence of a string inside another string

strrev() Reverses a string

strripos() Finds the position of the last occurrence of a string inside another string (case-insensitive)

strrpos() Finds the position of the last occurrence of a string inside another string (case-sensitive)

strspn() Returns the number of characters found in a string that contains only characters from a specified charlist

strstr() Finds the first occurrence of a string inside another string (case-sensitive)

strtok() Splits a string into smaller strings

strtolower() Converts a string to lowercase letters

strtoupper() Converts a string to uppercase letters

strtr() Translates certain characters in a string

substr() Returns a part of a string

substr_compare() Compares two strings from a specified start position (binary safe and optionally case-sensitive)

substr_count() Counts the number of times a substring occurs in a string

substr_replace() Replaces a part of a string with another string

trim() Removes whitespace or other characters from both sides of a string

ucfirst() Converts the first character of a string to uppercase

ucwords() Converts the first character of each word in a string to uppercase

vfprintf() Writes a formatted string to a specified output stream

vprintf() Outputs a formatted string

vsprintf() Writes a formatted string to a variable

wordwrap() Wraps a string to a given number of characters

44|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

D. Learning Activities

Activity 2.1
Write a PHP script to get the PHP version and configuration information.

Activity 2.2
Write a PHP script to display the strings “I am a PHP developer” with variable name $me.

Activity 2.3
$var = 'PHP Tutorial'. Put this variable into the title section, h3 tag and as an anchor text within an HTML document.

Activity 2.4
Create a simple HTML form and accept the user name and display the name with a greeting “Hello” through PHP echo statement.
Sample Output

Activity 2.5
Make a PHP script that make simple calculator

Activity 2.5
Make a PHP script that can perform simple addition.
Sample Output

E. Assessment
1. Which of the variables is float?
a. $qty = “1.01”; c. $qty = ‘1.01’;
b. $qty = 1; d. $qty = 1.001;
45|Web System and Technologies 2
Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

2. Which of the following is correct when declaring a constant?


a. Define {‘Price’, 10}; c. define (price, 100);
b. define (‘Price’); d. define (‘price’, 100);
3. Which of the following variables is visible everywhere within the script?
a. Constant c. Built-in superglobal variables
b. Global variables d. Variables declared inside the function
4. Which of the following is an string operator?
a. Addition (+) c. Less than (<)
b. Identical (===) d. Concatenation (.
5. Which of the following is a logical operator?
a. && c. <>
b. != d. %=
6. Which of the following has an equivalent of $a= $a + $b?
a. $a =+ $b c. $b += $a
b. $a += $b d. $b =+ $a
7. Which of the following is NOT TRUE about PHP variables?
a. All variables in PHP are denoted with a leading dollar sign ($).
b. PHP does a good job of automatically converting types from one to another when necessary.
c. The value of a variable is the value of its most recent assignment.
d. PHP variable has only 5 datatypes
8. In PHP operators, which of the following is an equal operator?
a. = c. ===
b. == d. !=
9. A variable that has a value is set once and then cannot be changed elsewhere in the script.
a. Variable variable c. Resource
b. Constant d. Arrays
10. It is an operator that are used with numeric values to write a value to a variable.
a. Assignment Operator c. Conditional Operator
b. Arithmetic Operator d. Logic Operator

REFERENCES
June Jamrich Parson and Dan O. (2014). New Perspective on Computer Concepts, Cengage Learning
https://www.tutorialspoint.com/php/php_variable_types.htm
https://www.w3schools.com/php/php_operators.asp
https://www.javatpoint.com/php-string

ACTIVITY RUBRICS

Program 5 points 3-4 points 1-2 points No point


Program execution Program executes Program executes Program does not
correctly with no with a minor (easily execute
syntax or runtime fixed error
errors
Correct output Program displays Output has minor Output has multiple Output is incorrect
correct output with no errors errors
errors
Code Structure and The code is hard to The code is not well The code is well The code is properly
Organization understand and lots of organized with minimal organized but there is named and organized
formatting error formatting error. a formatting error. with no formatting
error.

46|Web System and Technologies 2


Learning Module |Prepared by: MARK JOSHUA V. QUIAMBAO

47|Web System and Technologies 2

You might also like