ITWM132 - Module 0 - Review
ITWM132 - Module 0 - Review
Prepared by:
Naycer Jeremy G. Tulas
n.tulas@bsu.edu.ph
09129412101
https://www.facebook.com/naycer.tulas
Review – What is PHP
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open-source
general-purpose scripting language that is especially suited for web development and can
be embedded into HTML. For example:
PHP pages contain HTML with embedded code that does "something" (in this case, output
"Hi, I'm a PHP script!"). When PHP parses a file, it looks for opening and closing tags, which
are <?php and ?> which tell PHP to start and stop interpreting the code between them.
Parsing in this manner allows PHP to be embedded in all sorts of different documents, as
everything outside of a pair of opening and closing tags is ignored by the PHP parser.
PHP requires two basic components to run; a web server and a browser. For the purposes of
this class, we will be using Apache as our web server. But to make it more convenient we
will be using the XAMPP package which includes not only Apache but MySQL as well. You
are free to choose which browser (Firefox, Google Chrome, Edge, etc..) and which text-
editor (Sublime Text, Visual Studio, Notepad ++, etc..) to use.
We will be more commonly working with bool, int, float, string, array, and object.
PHP is loosely typed. Meaning that you do not need to declare the type, the parser will infer
it from your code. This is known as type juggling.
An array stores multiple values in one single variable. Classes and objects are the two main
aspects of object-oriented programming. A class is a template for objects, and an object is
an instance of a class.
Expressions
Expressions are the most important building blocks of PHP. In PHP, almost anything you
write is an expression. The simplest yet most accurate way to define an expression is
"anything that has a value".
The most basic forms of expressions are constants and variables. When you type $a = 5,
you're assigning 5 into $a. 5, obviously, has the value 5, or in other words 5 is an expression
with the value of 5 (in this case, 5 is an integer constant).
After this assignment, you'd expect $a's value to be 5 as well, so if you wrote $b = $a, you'd
expect it to behave just as if you wrote $b = 5. In other words, $a is an expression with the
value of 5 as well. If everything works right, this is exactly what will happen.
Operators
PHP, just like any other programming language, has support for various operators like
arithmetic operators, assignment operators, logical operators, and others.
Control Structures/Statements
Any PHP script is built out of a series of statements including control statements/structures.
The various control structures are described here.
Functions
A function may be defined using syntax such as the following:
Any valid PHP code may appear inside a function, even other functions and class definitions.
Function names follow the same rules as other labels in PHP. A valid function name starts
with a letter or underscore, followed by any number of letters, numbers, or underscores.
Running Your First PHP Script
Download XAMPP from here. I am assuming that all of us are using Windows (either 7 or 10)
64-bit. Make sure that you download version 8.1.6.
Follow the installation instructions. Keep the default settings especially the installation
folder so that all further instructions are uniform.
From now on, every time we want to use PHP. We should start the Apache Module from
the XAMPP control panel.
Navigate to Local Disk C:\xampp\htdocs. All your future projects will be stored here. Create
a folder and name it ITWM132.
The server looks for specifically named files as the first page of your website, also known as
the index page. The default order of index file names our particular servers look through is
index.htm, index.html, index.php, and finally default.htm.
Inside the ITWM132 folder, create an index.php file. You can use any text editor to edit the
index.php file. I will personally be using Sublime Text 3.
Copy and paste the code below into your index.php. The short snippet below demonstrates
simple concepts such as variable declaration, assignment operators, and a basic control
statement.
You can access your page by opening any web browser and navigating to
http://localhost/ITWM132/
Try to toggle the control statement by setting the variable $show_last_name to false.
? Module 0: Quiz and Laboratory Activity
(Answer in respective Google Classrooms)
Prepared by:
Naycer Jeremy G. Tulas
n.tulas@bsu.edu.ph
09129412101
https://www.facebook.com/naycer.tulas