Lecture15-Intro To PHP
Lecture15-Intro To PHP
BIO400
Lecture 15
INTRODUCTION TO
PHP
OVERVIEW OF PHP
• PHP is a server-side scripting language, like ASP
• PHP supports many databases (MySQL, Informix, Oracle,
Sybase, Solid, PostgreSQL, Generic ODBC, etc.)
• PHP is an open source software (OSS)
• PHP runs on different platforms (Windows, Linux, Unix, etc.)
• PHP is compatible with almost all servers used today
(Apache, IIS, etc.)
• PHP is FREE to download from the official PHP resource:
www.php.net
What is a PHP File?
1 URL 2
$var_name = value;
String Variables in PHP
• In PHP, variable names must start with a
dollar sign ($).
<?php
$txt="Hello World";
echo $txt;
?>
PHP Variables Examples
• <?php
$txt = "Hello world!"; <?php
$x = 5; $txt = “Fruits of all
flavors";
$y = 10.5; echo "I like $txt!";
?> ?>
<?php
$variable1 = 2;
$variable2 = 9;
$variable3 = $variable1 + $variable2;
echo $variable3;
?>
Rules for PHP variables:
• A variable starts with the $ sign, followed by the name
of the variable
• A variable name must start with a letter or the
underscore character
• A variable name must not contain spaces.
• A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive ($age and $AGE are
two different variables)
PHP Variables-Concatenation
<?php
$variable1 = 2;
$variable2 = 9;
$variable3 = $variable1 + $variable2;
echo $variable1 . " + " . $variable2 . " = "
. $variable3;
?>
17
OUTPUTS
• Output from a PHP script is HTML that is sent to the
browser
• HTML is sent to the browser through standard output
• There are three ways to produce output: echo, print, and
printf
– echo and print take a string, but will coerce other values to strings
echo “Test“,”None”; # More than one parameter acceptable
echo("first <br />", $sum) # More than one,
print "Welcome to my site!"; # Only one
printf – same like C
• PHP code is placed in the body of an HTML document
21
OUTPUTS
• An Example:
<html>
<head><title> Trivial php example </title>
</head>
<body>
<?php
print "Welcome to my Web site!";
?>
</body>
</html>
echo and print Difference