Unit I - Introduction to PHP
1. Introduction to PHP
1.1 Introduction to Static and Dynamic Websites
Static Website
-
Content is fixed and does not change automatically.
-
Created using HTML and CSS.
-
Same content is shown to all users.
Example:
A college notice page written only in HTML.
Dynamic Website
-
Content changes based on user interaction or database.
-
Uses server-side languages like PHP.
-
Can display different data to different users.
Example:
Login system, online result system, feedback form.
1.2 Introduction to PHP and Its History
-
PHP stands for Hypertext Preprocessor.
-
It is a server-side scripting language.
-
PHP code runs on the server and sends output to the browser as HTML.
History of PHP
-
Created by Rasmus Lerdorf in 1994.
-
Initially called Personal Home Page.
-
Later developed into a powerful web development language.
-
Widely used with MySQL for database-driven websites.
1.3 Basic PHP Syntax and File Structure
-
PHP files use the extension
.php -
PHP code is written inside
<?php ?>tags. -
Statements end with a semicolon (;)
Basic PHP Program
File Structure
-
PHP code can be written inside HTML.
1.4 Output Statements: echo and print
echo
-
Used to display output.
-
Faster than print.
-
Can display multiple values.
-
Used to display output.
-
Returns value
1.
1.5 PHP Variables and Value Types
Variables
-
Used to store data.
-
Start with
$symbol. -
No need to declare data type.
Value Types (Data Types)
-
String –
"Hello" -
Integer –
25 -
Float –
10.5 -
Boolean –
true / false -
Array
-
NULL
1.6 PHP Constants and Magic Constants
Constants
-
Value cannot be changed.
-
Defined using
define().
Magic Constants
-
Predefined constants.
-
Start and end with
__.
| Magic Constant | Description |
|---|---|
__LINE__ | Current line number |
__FILE__ | File path |
__DIR__ | Directory path |
__FUNCTION__ | Function name |
1.7 PHP Operators and Their Precedence
1. Arithmetic Operators
| Operator | Use |
|---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulus |
2. Increment and Decrement Operators
3. Assignment Operators
4. Logical Operators
| Operator | Meaning |
|---|---|
&& | AND |
| ` | |
! | NOT |
5. Bitwise Operators
-
Work on binary values.
1.8 Decision-Making Statements
if Statement
if-else Statement
else-if Clause
switch-case Statement
1.9 Loops
while Loop
for Loop
Nested Loop
break and continue
Comments
Post a Comment