PHP Lec1
PHP Lec1
System
&
Technologies
Lecture 1
PHP
PHP - Introduction
• The PHP Hypertext Preprocessor (PHP) is a programming language that allows
web developers to create dynamic content that interacts with databases
• PHP is a recursive acronym for "PHP: Hypertext Preprocessor".
• PHP is a server side scripting language that is embedded in HTML. It is used to
manage dynamic content, databases, session tracking, even build entire e-
commerce sites.
• It is integrated with a number of popular databases, including MySQL,
PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.
• PHP is a case sensitive language
Basic PHP Syntax
• A PHP script starts with <?php and ends with ?>:
• <?php
// PHP code goes here
?>
• The default file extension for PHP files is ".php".
Comments in PHP
<?php
// This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
// You can also use comments to leave out parts of a code line
$x = 5 /* + 15 */ + 5;
echo $x;
?>
Creating (Declaring) PHP Variables
• in PHP, a variable starts with the $ sign, followed by the name of the
variable:
$txt = "Hello world!";
$x = 5;
$y = 10.5;
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 cannot start with a number
• 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)
Output Variables
• <?php
$txt = “MIT UOS ";
echo “MY CLASS IS $txt!";
?>
PHP is a Loosely Typed Language
• In the example above, notice that we did not have to tell PHP which data
type the variable is.
• PHP automatically converts the variable to the correct data type,
depending on its value.