SlideShare a Scribd company logo
1 of 12
Download to read offline
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
1
Chapter 5
Part I
PHP
 PHP is a server scripting language, and a powerful tool for making
dynamic and interactive Web pages.
 PHP scripts are executed on the server.
Basic PHP Syntax
A PHP script can be placed anywhere in the document.
A PHP script starts with <?php and ends with ?>:
<?php
// PHP code goes here
?>
The default file extension for PHP files is ".php".
A PHP file normally contains HTML tags, and some PHP scripting code.
Below, we have an example of a simple PHP file, with a PHP script that
uses a built-in PHP function "echo" to output the text "Hello World!" on
a web page:
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
2
</body>
</html>
PHP Variables
Variables are "containers" for storing information.
Creating (Declaring) PHP Variables: In PHP, a variable starts with the $ sign,
followed by the name of the variable:
<!DOCTYPE html>
<html>
<body>
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
echo $txt;
echo "<br>";
echo $x;
echo "<br>";
echo $y;
?>
</body>
</html>
PHP echo and print Statements
In PHP there are two basic ways to get output: echo.
The echo statement can be used with or without parentheses: echo or
echo().
<!DOCTYPE html>
<html>
<body>
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
3
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple parameters.";
?>
</body>
</html>
The following example shows how to output text and variables with the
echo statement:
<!DOCTYPE html>
<html>
<body>
<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 5;
$y = 4;
echo "<h2>" . $txt1 . "</h2>";
echo "Study PHP at " . $txt2 . "<br>";
echo $x + $y;
?>
</body>
</html>
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
4
PHP Data Types
Variables can store data of different types, and different data types can
do different things.
PHP supports the following data types:
 String
 Integer
 Float (floating point numbers - also called double)
 Boolean
 Array
 NULL
1. PHP String
A string is a sequence of characters, like "Hello world!".
A string can be any text inside quotes. You can use single or double quotes:
<!DOCTYPE html>
<html>
<body>
<?php
$x = "Hello world!";
$y = 'Hello world!';
echo $x;
echo "<br>";
echo $y;
?>
</body>
</html
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
5
2. PHP Integer
In the following example $x is an integer. The PHP var_dump() function
returns the data type and value:
<!DOCTYPE html>
<html>
<body>
<?php
$x = 5985;
var_dump($x);
?>
</body>
</html>
3. PHP Float
In the following example $x is a float. The PHP var_dump() function
returns the data type and value:
<!DOCTYPE html>
<html>
<body>
<?php
$x = 10.365;
var_dump($x);
?>
</body>
</html>
4. PHP Boolean
A Boolean represents two possible states: TRUE or FALSE.
$x = true;
$y = false;
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
6
5. PHP Array
An array stores multiple values in one single variable.
In the following example $cars is an array. The PHP var_dump()
function returns the data type and value:
<!DOCTYPE html>
<html>
<body>
<?php
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
?>
</body>
</html>
6. PHP NULL Value
Null is a special data type which can have only one value: NULL.
A variable of data type NULL is a variable that has no value assigned to it.
<!DOCTYPE html>
<html>
<body>
<?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
</body>
</html>
PHP Strings
A string is a sequence of characters, like "Hello world!".
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
7
Get The Length of a String
The PHP strlen() function returns the length of a string.
<?php
echo strlen("Hello world!"); // outputs 12
?>
Count The Number of Words in a String
The PHP str_word_count() function counts the number of words in a
string:
<?php
echo str_word_count("Hello world!"); // outputs 2
?>
Reverse a String
The PHP strrev() function reverses a string:
<?php
echo strrev("Hello world!"); // outputs !dlrow olleH
?>
Search For a Specific Text Within a String
The PHP strpos() function searches for a specific text within a string.
If a match is found, the function returns the character position of the
first match. If no match is found, it will return FALSE.
<?php
echo strpos("Hello world!", "world"); // outputs 6
?>
Replace Text Within a String
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
8
The PHP str_replace() function replaces some characters with some
other characters in a string.
<?php
echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello
Dolly!
?>
PHP Operators
Operators are used to perform operations on variables and values.
PHP Arithmetic Operators
The PHP arithmetic operators are used with numeric values to perform
common arithmetical operations, such as addition, subtraction,
multiplication etc.
Operator Name Example Result
+ Addition $x + $y Sum of $x and $y
- Subtraction $x - $y Difference of $x and $y
* Multiplication $x * $y Product of $x and $y
/ Division $x / $y Quotient of $x and $y
% Modulus $x % $y Remainder of $x divided by $y
** Exponentiation $x ** $y
Result of raising $x to the $y'th
power (Introduced in PHP 5.6)
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
9
PHP Assignment Operators
The PHP assignment operators are used with numeric values to write a
value to a variable.
Assignment Same as... Description
x = y x = y
The left operand gets set to the value of the
expression on the right
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus
PHP Comparison Operators
The PHP comparison operators are used to compare two values
(number or string):
Operator Name Example Result
== Equal $x == $y Returns true if $x is equal to $y
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
10
=== Identical $x === $y
Returns true if $x is equal to $y,
and they are of the same type
!= Not equal $x != $y Returns true if $x is not equal to $y
<> Not equal $x <> $y Returns true if $x is not equal to $y
!== Not identical $x !== $y
Returns true if $x is not equal to
$y, or they are not of the same
type
> Greater than $x > $y Returns true if $x is greater than $y
< Less than $x < $y Returns true if $x is less than $y
>=
Greater than or
equal to
$x >= $y
Returns true if $x is greater than or
equal to $y
<=
Less than or equal
to
$x <= $y
Returns true if $x is less than or
equal to $y
PHP Increment / Decrement Operators
Operator Name Description
++$x Pre-increment Increments $x by one, then returns $x
$x++ Post-increment Returns $x, then increments $x by one
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
11
--$x Pre-decrement Decrements $x by one, then returns $x
$x-- Post-decrement Returns $x, then decrements $x by one
PHP Logical Operators
The PHP logical operators are used to combine conditional statements.
Operator Name Example Result
And And $x and $y
True if both $x and $y are
true
Or Or $x or $y True if either $x or $y is true
Xor Xor $x xor $y
True if either $x or $y is true,
but not both
&& And $x && $y
True if both $x and $y are
true
|| Or $x || $y True if either $x or $y is true
! Not !$x True if $x is not true
PHP String Operators
Operator Name Example Result
. Concatenation $txt1 . $txt2
Concatenation of
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
12
$txt1 and $txt2
.=
Concatenation
assignment
$txt1 .= $txt2
Appends $txt2 to
$txt1
PHP Array Operators
Operator Name Example Result
+ Union $x + $y Union of $x and $y
== Equality $x == $y
Returns true if $x and $y have the
same key/value pairs
=== Identity $x === $y
Returns true if $x and $y have the
same key/value pairs in the same
order and of the same types
!= Inequality $x != $y Returns true if $x is not equal to $y
<> Inequality $x <> $y Returns true if $x is not equal to $y
!== Non-identity $x !== $y
Returns true if $x is not identical to
$y

More Related Content

What's hot (20)

Php
PhpPhp
Php
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
PHP
PHPPHP
PHP
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Ph pbasics
Ph pbasicsPh pbasics
Ph pbasics
 
PHP
PHPPHP
PHP
 
Php essentials
Php essentialsPhp essentials
Php essentials
 
Php
PhpPhp
Php
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
Constructor and encapsulation in php
Constructor and encapsulation in phpConstructor and encapsulation in php
Constructor and encapsulation in php
 
Prersentation
PrersentationPrersentation
Prersentation
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web Programming
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Unit 1 php_basics
Unit 1 php_basicsUnit 1 php_basics
Unit 1 php_basics
 

Viewers also liked

Юзабилити-рейтинг мобильных банков 2015
Юзабилити-рейтинг мобильных банков 2015Юзабилити-рейтинг мобильных банков 2015
Юзабилити-рейтинг мобильных банков 2015Ася Жукова
 
Medict - Medical Jargon Translator
Medict - Medical Jargon TranslatorMedict - Medical Jargon Translator
Medict - Medical Jargon TranslatorHEMA Biosciences
 
LAPORAN PRAKERIN PT. TRAVELKU JAYA SELALU
LAPORAN PRAKERIN PT. TRAVELKU JAYA SELALULAPORAN PRAKERIN PT. TRAVELKU JAYA SELALU
LAPORAN PRAKERIN PT. TRAVELKU JAYA SELALUAdrian Hartanto Lokaria
 
Module2 block1section6
Module2 block1section6Module2 block1section6
Module2 block1section6dsanchop
 
Финансовые продукты с человеческим лицом (Андрей Сыцко, Id Finance)
Финансовые продукты с человеческим лицом (Андрей Сыцко, Id Finance)Финансовые продукты с человеческим лицом (Андрей Сыцко, Id Finance)
Финансовые продукты с человеческим лицом (Андрей Сыцко, Id Finance)PCampRussia
 
Superlativo excepciones
Superlativo   excepcionesSuperlativo   excepciones
Superlativo excepcionesspanisch
 

Viewers also liked (12)

Fainal 12
Fainal 12Fainal 12
Fainal 12
 
Юзабилити-рейтинг мобильных банков 2015
Юзабилити-рейтинг мобильных банков 2015Юзабилити-рейтинг мобильных банков 2015
Юзабилити-рейтинг мобильных банков 2015
 
framily_abstract
framily_abstractframily_abstract
framily_abstract
 
AME Support & Service
AME Support & Service AME Support & Service
AME Support & Service
 
Medict - Medical Jargon Translator
Medict - Medical Jargon TranslatorMedict - Medical Jargon Translator
Medict - Medical Jargon Translator
 
LAPORAN PRAKERIN PT. TRAVELKU JAYA SELALU
LAPORAN PRAKERIN PT. TRAVELKU JAYA SELALULAPORAN PRAKERIN PT. TRAVELKU JAYA SELALU
LAPORAN PRAKERIN PT. TRAVELKU JAYA SELALU
 
Module2 block1section6
Module2 block1section6Module2 block1section6
Module2 block1section6
 
Финансовые продукты с человеческим лицом (Андрей Сыцко, Id Finance)
Финансовые продукты с человеческим лицом (Андрей Сыцко, Id Finance)Финансовые продукты с человеческим лицом (Андрей Сыцко, Id Finance)
Финансовые продукты с человеческим лицом (Андрей Сыцко, Id Finance)
 
PKM-GT Kuliner
PKM-GT KulinerPKM-GT Kuliner
PKM-GT Kuliner
 
Superlativo excepciones
Superlativo   excepcionesSuperlativo   excepciones
Superlativo excepciones
 
tabela verdade
  tabela verdade  tabela verdade
tabela verdade
 
manu seo
manu seomanu seo
manu seo
 

Similar to PHP-Part1

Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPwahidullah mudaser
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Gheyath M. Othman
 
Php web development
Php web developmentPhp web development
Php web developmentRamesh Gupta
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQLArti Parab Academics
 
Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomerShivi Tomer
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_masterjeeva indra
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)Guni Sonow
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009cwarren
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaDeepak Rajput
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting languageElmer Concepcion Jr.
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 

Similar to PHP-Part1 (20)

Php
PhpPhp
Php
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
Php web development
Php web developmentPhp web development
Php web development
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
Basic php 5
Basic php 5Basic php 5
Basic php 5
 
Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomer
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
 
Day1
Day1Day1
Day1
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in India
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
Php tutorialw3schools
Php tutorialw3schoolsPhp tutorialw3schools
Php tutorialw3schools
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
PHP and MySQL.ppt
PHP and MySQL.pptPHP and MySQL.ppt
PHP and MySQL.ppt
 

More from Ahmed Saihood (11)

Sessions &Cookies
Sessions &CookiesSessions &Cookies
Sessions &Cookies
 
PHP-Part4
PHP-Part4PHP-Part4
PHP-Part4
 
PHP-Part3
PHP-Part3PHP-Part3
PHP-Part3
 
PHP-Part2
PHP-Part2PHP-Part2
PHP-Part2
 
HTTP & HTTPs
HTTP & HTTPsHTTP & HTTPs
HTTP & HTTPs
 
CSS
CSSCSS
CSS
 
XHTML
XHTMLXHTML
XHTML
 
HTML-Forms
HTML-FormsHTML-Forms
HTML-Forms
 
HTML-Part2
HTML-Part2HTML-Part2
HTML-Part2
 
HTML-Part1
HTML-Part1HTML-Part1
HTML-Part1
 
internet basics
internet basics internet basics
internet basics
 

Recently uploaded

Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Roomdivyansh0kumar0
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$kojalkojal131
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Deliverybabeytanya
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts servicesonalikaur4
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607dollysharma2066
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirtrahman018755
 
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 

Recently uploaded (20)

Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
 
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 

PHP-Part1

  • 1. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 1 Chapter 5 Part I PHP  PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.  PHP scripts are executed on the server. Basic PHP Syntax A PHP script can be placed anywhere in the document. A PHP script starts with <?php and ends with ?>: <?php // PHP code goes here ?> The default file extension for PHP files is ".php". A PHP file normally contains HTML tags, and some PHP scripting code. Below, we have an example of a simple PHP file, with a PHP script that uses a built-in PHP function "echo" to output the text "Hello World!" on a web page: <!DOCTYPE html> <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?>
  • 2. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 2 </body> </html> PHP Variables Variables are "containers" for storing information. Creating (Declaring) PHP Variables: In PHP, a variable starts with the $ sign, followed by the name of the variable: <!DOCTYPE html> <html> <body> <?php $txt = "Hello world!"; $x = 5; $y = 10.5; echo $txt; echo "<br>"; echo $x; echo "<br>"; echo $y; ?> </body> </html> PHP echo and print Statements In PHP there are two basic ways to get output: echo. The echo statement can be used with or without parentheses: echo or echo(). <!DOCTYPE html> <html> <body>
  • 3. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 3 <?php echo "<h2>PHP is Fun!</h2>"; echo "Hello world!<br>"; echo "I'm about to learn PHP!<br>"; echo "This ", "string ", "was ", "made ", "with multiple parameters."; ?> </body> </html> The following example shows how to output text and variables with the echo statement: <!DOCTYPE html> <html> <body> <?php $txt1 = "Learn PHP"; $txt2 = "W3Schools.com"; $x = 5; $y = 4; echo "<h2>" . $txt1 . "</h2>"; echo "Study PHP at " . $txt2 . "<br>"; echo $x + $y; ?> </body> </html>
  • 4. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 4 PHP Data Types Variables can store data of different types, and different data types can do different things. PHP supports the following data types:  String  Integer  Float (floating point numbers - also called double)  Boolean  Array  NULL 1. PHP String A string is a sequence of characters, like "Hello world!". A string can be any text inside quotes. You can use single or double quotes: <!DOCTYPE html> <html> <body> <?php $x = "Hello world!"; $y = 'Hello world!'; echo $x; echo "<br>"; echo $y; ?> </body> </html
  • 5. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 5 2. PHP Integer In the following example $x is an integer. The PHP var_dump() function returns the data type and value: <!DOCTYPE html> <html> <body> <?php $x = 5985; var_dump($x); ?> </body> </html> 3. PHP Float In the following example $x is a float. The PHP var_dump() function returns the data type and value: <!DOCTYPE html> <html> <body> <?php $x = 10.365; var_dump($x); ?> </body> </html> 4. PHP Boolean A Boolean represents two possible states: TRUE or FALSE. $x = true; $y = false;
  • 6. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 6 5. PHP Array An array stores multiple values in one single variable. In the following example $cars is an array. The PHP var_dump() function returns the data type and value: <!DOCTYPE html> <html> <body> <?php $cars = array("Volvo","BMW","Toyota"); var_dump($cars); ?> </body> </html> 6. PHP NULL Value Null is a special data type which can have only one value: NULL. A variable of data type NULL is a variable that has no value assigned to it. <!DOCTYPE html> <html> <body> <?php $x = "Hello world!"; $x = null; var_dump($x); ?> </body> </html> PHP Strings A string is a sequence of characters, like "Hello world!".
  • 7. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 7 Get The Length of a String The PHP strlen() function returns the length of a string. <?php echo strlen("Hello world!"); // outputs 12 ?> Count The Number of Words in a String The PHP str_word_count() function counts the number of words in a string: <?php echo str_word_count("Hello world!"); // outputs 2 ?> Reverse a String The PHP strrev() function reverses a string: <?php echo strrev("Hello world!"); // outputs !dlrow olleH ?> Search For a Specific Text Within a String The PHP strpos() function searches for a specific text within a string. If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE. <?php echo strpos("Hello world!", "world"); // outputs 6 ?> Replace Text Within a String
  • 8. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 8 The PHP str_replace() function replaces some characters with some other characters in a string. <?php echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly! ?> PHP Operators Operators are used to perform operations on variables and values. PHP Arithmetic Operators The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc. Operator Name Example Result + Addition $x + $y Sum of $x and $y - Subtraction $x - $y Difference of $x and $y * Multiplication $x * $y Product of $x and $y / Division $x / $y Quotient of $x and $y % Modulus $x % $y Remainder of $x divided by $y ** Exponentiation $x ** $y Result of raising $x to the $y'th power (Introduced in PHP 5.6)
  • 9. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 9 PHP Assignment Operators The PHP assignment operators are used with numeric values to write a value to a variable. Assignment Same as... Description x = y x = y The left operand gets set to the value of the expression on the right x += y x = x + y Addition x -= y x = x - y Subtraction x *= y x = x * y Multiplication x /= y x = x / y Division x %= y x = x % y Modulus PHP Comparison Operators The PHP comparison operators are used to compare two values (number or string): Operator Name Example Result == Equal $x == $y Returns true if $x is equal to $y
  • 10. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 10 === Identical $x === $y Returns true if $x is equal to $y, and they are of the same type != Not equal $x != $y Returns true if $x is not equal to $y <> Not equal $x <> $y Returns true if $x is not equal to $y !== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the same type > Greater than $x > $y Returns true if $x is greater than $y < Less than $x < $y Returns true if $x is less than $y >= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y <= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y PHP Increment / Decrement Operators Operator Name Description ++$x Pre-increment Increments $x by one, then returns $x $x++ Post-increment Returns $x, then increments $x by one
  • 11. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 11 --$x Pre-decrement Decrements $x by one, then returns $x $x-- Post-decrement Returns $x, then decrements $x by one PHP Logical Operators The PHP logical operators are used to combine conditional statements. Operator Name Example Result And And $x and $y True if both $x and $y are true Or Or $x or $y True if either $x or $y is true Xor Xor $x xor $y True if either $x or $y is true, but not both && And $x && $y True if both $x and $y are true || Or $x || $y True if either $x or $y is true ! Not !$x True if $x is not true PHP String Operators Operator Name Example Result . Concatenation $txt1 . $txt2 Concatenation of
  • 12. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 12 $txt1 and $txt2 .= Concatenation assignment $txt1 .= $txt2 Appends $txt2 to $txt1 PHP Array Operators Operator Name Example Result + Union $x + $y Union of $x and $y == Equality $x == $y Returns true if $x and $y have the same key/value pairs === Identity $x === $y Returns true if $x and $y have the same key/value pairs in the same order and of the same types != Inequality $x != $y Returns true if $x is not equal to $y <> Inequality $x <> $y Returns true if $x is not equal to $y !== Non-identity $x !== $y Returns true if $x is not identical to $y