Professional Documents
Culture Documents
Part 1
Course Title: Web Systems and Technologies
Course Code: CS-3548
Instructor: Nauman Ahmed
PAKISTAN INSTITUTE OF ENGINEERING & 1
TECHNOLOGY
OUTLINE
Input B Data
r HTML&
o PHP
User Data Web
w Program
Server
s (CGI)
e HTML
Output Document Data
r
HTML Flow
Document
Database
Management
System
• Basic Syntax
– Semicolons
– The $ symbol
• Variables
– String variables
– Numeric variables
– Arrays $team = array('Bill', 'Mary', 'Mike', 'Chris', 'Anne');
– Two-dimensional arrays
• Naming Conventions
• Variable names must start with a letter of the alphabet or the _
(underscore) character.
• Variable names can contain only the characters a–z, A–Z, 0–9, and _
(underscore).
• Variable names may not contain spaces. If a variable must comprise
more than one
• word, it should be separated with the _ (underscore) character (e.g.,
$user_name).
• Variable names are case-sensitive. The variable $High_Score is not
the same as the variable $high_score.
• Operators
– Arithmetic operators
– Assignment operators
– Comparison operators
– Logical operators
• Variable Assignment
– Variable incrementing and decrementing
• += and −= operators
– String concatenation
• Escaping characters
PAKISTAN INSTITUTE OF ENGINEERING & 11
TECHNOLOGY
The Structure of PHP
• Multiple-Line Commands
• Variable Typing
– PHP is a very loosely typed language.
Example 3-10. Automatic conversion from a number to a string
<?php
$number = 12345 * 67890;
echo substr($number, 3, 1);
?>
• Constants
– define("ROOT_LOCATION", "/usr/local/www/");
» Holds the location of your server root.
• $directory = ROOT_LOCATION;
• The Difference Between the echo and print Commands
– The differences are small: echo has no return value while print has a
return value of 1 so it can be used in expressions. echo can take
multiple parameters (although such usage is rare) while print can
take one argument. echo is marginally faster than print.
» The echo statement can be used with or without parentheses:
echo or echo().
PAKISTAN INSTITUTE OF ENGINEERING & 14
TECHNOLOGY
The Structure of PHP
• Functions
– function test($timestamp){ return date("l F jS Y", $timestamp);}
• Variable Scope
– Local variables
– Global variables
» global $is_logged_in;
– Static variables
» static $count = 0; (keep its value for the next time the function is
called)
– Superglobal variables
PAKISTAN INSTITUTE OF ENGINEERING & 17
TECHNOLOGY