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

Lesson 9 PHP - Introduction

This document provides an introduction to PHP. It discusses installing PHP, PHP syntax rules, variables, decision-making statements like if/else statements and switch statements, and loops like for, while, and do-while loops. The document also mentions features of PHP that make it better than other server-side languages and different variable scopes in PHP.

Uploaded by

1045858
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Lesson 9 PHP - Introduction

This document provides an introduction to PHP. It discusses installing PHP, PHP syntax rules, variables, decision-making statements like if/else statements and switch statements, and loops like for, while, and do-while loops. The document also mentions features of PHP that make it better than other server-side languages and different variable scopes in PHP.

Uploaded by

1045858
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Web Design and Development Lesson 9

Lesson 9: PHP Introduction

Lesson 9: PHP Introduction ............................................................................................................ 1


9.1 Introduction ..................................................................................................................... 2
9.1.1. Install PHP ................................................................................................................. 2
9.2 PHP Syntax Rules ............................................................................................................. 2
9.3 PHP Variables ................................................................................................................... 3
9.4 PHP Decision Making Statements ................................................................................... 4
9.4.1. The if statement ........................................................................................................ 4
9.4.2. The if…else statement............................................................................................... 4
9.4.3. The if..else if.. else statement ................................................................................... 5
9.4.4. The Switch statement ............................................................................................... 5
9.5 PHP Loops ........................................................................................................................ 6
9.5.1. For Loop .................................................................................................................... 6
9.5.2. While Loop ................................................................................................................ 6
9.5.3. Do-While Loop .......................................................................................................... 6
Lesson 9 Discussion Session ....................................................................................................... 7

Compiled by: Karari E.K email: cats.mwalimu@gmail.com 1


Web Design and Development Lesson 9

9.1 Introduction
PHP (Hypertext Pre-processor) is a web server-side programming language. It enables
developers to build web applications that interact with databases.
PHP isn't the only code that involves server-side scripting, and server-side scripting isn't limited
to websites. Other server-side programming languages are Python, Ruby, C#, C++, and Java.
There are many instances of server-side scripting, which provides a customized experience for
users.
9.1.1. Install PHP
To install PHP, we will suggest you to install AMP (Apache, MySQL, PHP) software stack. It is
available for all operating systems. There are many AMP options available in the market that
are given below:
o WAMP for Windows LAMP for Linux, MAMP for Mac SAMP for Solaris
o XAMPP (Cross, Apache, MySQL, PHP, Perl) for Cross Platform: It includes some other
components too such as FileZilla, OpenSSL, Webalizer, Mercury Mail, etc.
9.2 PHP Syntax Rules
1. All the php code in a php script should be enclosed within <?php and ?>, else it
will not be considered as php code. Adding php code inside the PHP tags is
known as Escaping to php.
<?php ... ?>
Apart from the standard <?php and ?>, you can also use the Short-open tags:
<? ... ?>
Or use the HTML script tags, like we do for adding JavaScript code in HTML
document:
<script language="PHP"> ... </script>
2. Every expression in PHP ends with a semicolon;
3. Commenting PHP code: Both single line and multi-line comments are supported
in PHP. For single line comment, we can either use # or // before the comment
line. For example:

Compiled by: Karari E.K email: cats.mwalimu@gmail.com 2


Web Design and Development Lesson 9

4. PHP is case sensitive, which means that a variable $tiger is not same as $Tiger.
Both of these, represent two different variables here. But all the predefined
keywords and functions like if, else, echo etc are case insensitive.

5. PHP uses curly braces to define a code block.

9.3 PHP Variables


Here we have a few basic rules that you must keep in mind while creating variables in
PHP.
1. A variable name will always start with a $ sign, followed by the variable name.
2. A variable name should not start with a numeric value. It can either start with an
alphabet or an underscore sign _.

Compiled by: Karari E.K email: cats.mwalimu@gmail.com 3


Web Design and Development Lesson 9

9.4 PHP Decision Making Statements


9.4.1. The if statement

9.4.2. The if…else statement

Compiled by: Karari E.K email: cats.mwalimu@gmail.com 4


Web Design and Development Lesson 9

9.4.3. The if..else if.. else statement

9.4.4. The Switch statement

Compiled by: Karari E.K email: cats.mwalimu@gmail.com 5


Web Design and Development Lesson 9

9.5 PHP Loops


9.5.1. For Loop

9.5.2. While Loop

9.5.3. Do-While Loop

Compiled by: Karari E.K email: cats.mwalimu@gmail.com 6


Web Design and Development Lesson 9

Lesson 9 Discussion Session


1. Discuss features of PHP that make it better than other server-side scripting languages.
2. Distinguish using examples local, global, and static variables in PHP.

Compiled by: Karari E.K email: cats.mwalimu@gmail.com 7

You might also like