Professional Documents
Culture Documents
Lecture1 Intro To PHP
Lecture1 Intro To PHP
What is PHP?
PHP stands for PHP: Hypertext Preprocessor
PHP is a server-side scripting language, like
ASP
PHP scripts are executed on the server
PHP supports many databases (MySQL,
Informix, Oracle, Sybase, Solid, PostgreSQL,
Generic ODBC, etc.)
PHP is an open source software (OSS)
PHP is free to download and use
Strengths of php
Performance
It is very fast
Scalability
Interfaces to many different database systems
MySQL,PostgreSQL, Oracle, dbm, FilePro, DB2, Hyperwave,
Informix, InterBase, and Sybase databases, among others. PHP 5 also has a
built-in SQL
Built-in libraries for many common web tasks
Low cost
Ease of learning and use
Strong object-oriented support
Portability
PHP is available for many different operating systems
Flexibility of development approach
Availability of source code
Availability of support and documentation
What is a PHP File?
Syntax
if (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";
?>
</body>
</html>
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri") {
echo "Hello!<br />";
echo "Have a nice weekend!";
echo "See you on Monday!";
}
?>
</body>
</html>
The ElseIf Statement
Syntax
if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>
</body>
</html>
The Switch Statement
Syntax
switch (expression) {
case label1:
code to be executed if expression = label1;
break;
case label2:
code to be executed if expression = label2;
break;
default:
code to be executed if expression is different from
both label1 and label2;
}
<html>
<body>
<?php
switch ($x) {
case 1: echo "Number 1";
break;
case 2: echo "Number 2";
break;
case 3: echo "Number 3";
break;
default: echo "No number between 1 and 3";
}
?>
</body>
</html>
What is an array?
There are three different kind of arrays:
Numeric array - An array with a numeric ID
key
Associative array - An array where each ID
key is associated with a value
Multidimensional array - An array
containing one or more arrays
Numeric Arrays
Syntax
while (condition)
code to be executed;
Example
<html>
<body>
<?php
$i=1;
while($i<=5) {
echo "The number is " . $i . "<br />";
$i++; }
?>
</body>
</html>
The do...while Statement