SlideShare una empresa de Scribd logo
1 de 66
PHP- Personal Home Page
PHP-Introduction
• PHP is a server scripting language, and a
powerful tool for making dynamic and
interactive Web pages.
• PHP is a widely-used, free, and efficient
alternative to competitors such as
Microsoft's ASP.
• PHP 7 is the latest stable release.
Why to learn PHP?
• Some of the key advantages of learning PHP:
 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 supports a large number of major protocols such as
POP3, IMAP, and LDAP. PHP4 added support for Java and
distributed object architectures (COM and CORBA), making n-
tier development a possibility for the first time.
 PHP Syntax is C-Like.
Characteristics of PHP
• Five important characteristics make PHP's practical
nature possible
1. Simplicity
2. Efficiency
3. Security
4. Flexibility
5. Familiarity
Applications of PHP
• PHP is one of the most widely used language over the web.
 PHP performs system functions, i.e. from files on a system it can
create, open, read, write, and close them.
 PHP can handle forms, i.e. gather data from files, save data to a
file, through email you can send data, return data to the user.
 You add, delete, modify elements within your database through
PHP.
 Access cookies variables and set cookies.
 Using PHP, you can restrict users to access some pages of your
website.
 It can encrypt data.
PHP - Environment
• In order to develop and run PHP Web pages three vital components
need to be installed on your computer system.
 Web Server − PHP will work with virtually all Web Server software,
including Microsoft's Internet Information Server (IIS) but then most
often used is freely available Apache Server. Download Apache for
free here − https://httpd.apache.org/download.cgi
 Database − PHP will work with virtually all database software,
including Oracle and Sybase but most commonly used is freely
available MySQL database. Download MySQL for free here
− https://www.mysql.com/downloads/
 PHP Parser − In order to process PHP script instructions a parser
must be installed to generate HTML output that can be sent to the
Web Browser.
History of PHP
PHP was originally created by a developer named Rasmus Lerdorf.
Features/Advantages of PHP
1.Performance
2.Portability(Platform Independent)
3.Ease Of Use(Familiarity with syntax)
4.Open Source
5.Embedded
6.Third-Party Application Support(Database Support)
7. A helpful PHP Community Support
• Error Reporting
• Loosely Typed Language
• Web servers Support
• Security
• Control
PHP Installation
• To start using PHP,
• Find a web host with PHP and MySQL support
• Install a web server on your own PC, and then install
PHP and MySQL
Set Up PHP on Your Own PC
• However, if your server does not support PHP, you
must:
1. install a web server
2. install PHP
3. install a database, such as MySQL
PHP Software Requirement
PHP Server
• The PHP Community Provides Some types of Software
Server solution under The GNU (General Public
License).
• These are the following:
1.WAMP Server
2.LAMP Server
3.MAMP Server
4.XAMPP Server
• WAMP for Windows
• LAMP for Linux
• MAMP for Mac
• SAMP for Solaris
• FAMP for FreeBSD
• XAMPP (Cross, Apache, MySQL, PHP, Perl) for Cross
Platform: It includes some other components too such
as FileZilla, OpenSSL, Webalizer, Mercury Mail, etc.
PHP Syntax
• A PHP script is executed on the server, and the plain
HTML result is sent back to the browser.
• 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
Basic Code Syntax
Example
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
Note: PHP statements end with a semicolon (;)
The PHP command ‘echo’ is used to output
the parameters passed to it
◦ The typical usage for this is to send data to the
client’s web-browser
Syntax
◦ void echo (string arg1 [, string argn...])
◦ In practice, arguments are not passed in
parentheses since echo is a language construct
rather than an actual function
Echo
• PHP echo statement can be used to print the string,
multi-line strings, escaping characters, variable, array,
etc.
• Some important points about the echo statement are:
• echo is a statement, which is used to display the output.
• echo can be used with or without parentheses: echo(), and
echo.
• echo does not return any value.
• We can pass multiple strings separated by a comma (,) in
echo.
• echo is faster than the print statement.
PHP echo: printing string
<?php
echo "Hello by PHP echo";
?>
Output:
Hello by PHP echo
PHP echo: printing multi line string
<?php
echo "Hello by PHP echo
this is multi line
text printed by
PHP echo statement
";
?>
Output:
Hello by PHP echo this is multi line text printed by PHP echo
statement
PHP echo: printing escaping characters
<?php
echo "Hello escape "sequence" chara
cters";
?>
Output:
Hello escape "sequence" characters
PHP echo: printing variable value
<?php
$msg="Hello JavaTpoint PHP";
echo "Message is: $msg";
?>
Output:
Message is: Hello JavaTpoint PHP
PHP echo and print statements
• More or less same. Both are used to display data.
But differences are small:
1. echo has no return value while
print has a return value of 1 so it can be used in
expressions.
2. echo can take multiple parameters while
print can take one argument.
3. echo is marginally faster than print
The PHP print Statement
The print statement can be used with or
without parentheses: print or print().
Display Text
The following example shows how to output
text with the print command (Notice that the
text can contain HTML markup):
Example
<?php
print "<h2>PHP is easy!</h2>";
print "Hello world!<br>";
print “Have a nice day!";
?>
Display Variables
The following example shows how to output text and
variables with the print statement:
Example
<?php
$txt1 = “Hello";
$txt2 = “PHP";
$x = 5;
$y = 4;
print "<h2>" . $txt1 . "</h2>";
print “Welcome to " . $txt2 . "<br>";
print $x + $y;
?>
PHP Case Sensitivity
• In PHP, keywords (e.g. if, else, while, echo, etc.), classes,
functions, and user-defined functions are not case-sensitive.
• In the example below, all three echo statements below are
equal and legal.
• <!DOCTYPE html>
<html>
<body>
<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>
</body>
</html>
• Note: All three echo statements are equal and valid
Example for case sensitive
<!DOCTYPE html>
<html>
<body>
<?php
$color = "red";
echo "My car is " . $color . "<br>";
echo "My house is " . $COLOR . "<br>";
echo "My boat is " . $coLOR . "<br>";
?>
</body>
</html>
• Note: Here $color, $COLOR, and $coLOR are treated as three
different variables . First statement is true.
PHP Comments
• A comment in PHP code is a line that is not executed as
a part of the program. Its only purpose is to be read by
someone who is looking at the code.
• Comments can be used to:
 Let others understand our code
 Remind yourself of what you did - Most programmers
have experienced coming back to their own work a
year or two years later and having to re-figure out
what they did. Comments can remind you of what you
were thinking when you wrote the code.
PHP supports several ways of commenting:
• Syntax for single-line comments
<!DOCTYPE html>
<html>
<body>
<?php
// This is a single-line comment
# This is also a single-line comment
?>
</body>
</html>
• Syntax for multiple-line comments:
<!DOCTYPE html>
<html>
<body>
<?php
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
?>
</body> </html>
PHP Variables
• Variables are "containers" for storing
information.
Creating (Declaring) PHP Variables
Example
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
PHP Variables
A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume).
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)
•Note: Remember that PHP variable names are case-
sensitive!
Output Variables
• The PHP echo statement is often used to
output data to the screen.
• The following example will show how to output
text and a variable:
Example 1
<?php
$txt = “PHP";
echo "I like $txt!";
?>
Example 2
<?php
$txt = “PHP";
echo "I like " . $txt . "!";
?>
Note: The above example will produce the same output
as the previous one.
Example 3
<?php
$x = 5;
$y = 4;
echo $x + $y;
?>
PHP Variables Scope
• In PHP, variables can be declared anywhere in the script
• The scope of a variable is the part of the script where
the variable can be referenced/used.
• PHP has three different variable scopes:
1. local
2. global
3. static
Global and Local Scope
• A variable declared outside a function has a GLOBAL
SCOPE and can only be accessed outside a function
Example - Variable with global scope
<?php
$x = 5; // global scope
function display() {
// using x inside this function will generate an error
echo "<p>Variable x inside function is: $x</p>";
}
display();
echo "<p>Variable x outside function is: $x</p>";
?>
• A variable declared within a function has a LOCAL SCOPE
and can only be accessed within that function
Example
Variable with local scope:
<?php
function display() {
$x = 5; // local scope
echo "<p>Variable x inside function is: $x</p>";
}
display();
// using x outside the function will generate an error
echo "<p>Variable x outside function is: $x</p>";
?>
PHP The static Keyword
• Normally, when a function is completed/executed, all of its
variables are deleted. However, sometimes we want a local
variable NOT to be deleted. We need it for a further job.
• So declare the variable as static
<?php
function display()
{
static $x = 0;
echo $x;
$x++;
}
display();
display();
display();
?>
The global keyword is used to access a global variable
from within a function.
To do this, use the global keyword before the variables
(inside the function):
PHP The global Keyword
Example
<?php
$x = 5;
$y = 10;
function add() {
global $x, $y;
$y = $x + $y;
}
add();
echo $y; // outputs 15
?>
GLOBALS
• PHP also stores all global variables in an array
called $GLOBALS[index].
• The index holds the name of the variable. This array is
also accessible from within functions and can be used to
update global variables directly.
The example above can be rewritten like this:
Example
<?php
$x = 5;
$y = 10;
function add() {
$GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
}
add();
echo $y; // outputs 15
?>
PHP Data Types
• Variables can store data of different types, and different
data types can do different things.
PHP supports the following data types:
1. String
2. Integer
3. Float (floating point numbers - also called double)
4. Boolean
5. Array
6. Object
7. NULL
8. Resource
PHP Numbers
PHP provides automatic data type conversion.
So, if you assign an integer value to a variable, the type
of that variable will automatically be an integer. Then, if
you assign a string to the same variable, the type will
change to a string.
Example:
$x=12;
$x=‘Hello’;
PHP Integers
• An integer is a number without any decimal part.
• Example: 2, 256, -256, 10358, -179567 are all integers.
• So, an integer data type is a non-decimal number between -2147483648 and
2147483647.
• Here are some rules for integers:
 An integer must have at least one digit
 An integer must not have a decimal point
 An integer can be either positive or negative
 Integers can be specified in three formats: decimal (10-based), hexadecimal
(16-based - prefixed with 0x) or octal (8-based - prefixed with 0)
• PHP has the following functions to check if the type of a variable
is integer:
 is_int()
 is_integer() - alias of is_int()
 is_long() - alias of is_int()
Check if the type of a variable is integer:
<?php
$x = 5985;
var_dump(is_int($x));
$x = 59.85;
var_dump(is_int($x));
?>
PHP Float
• A float is a number with a decimal point or a number in
exponential form.
• 2.0, 256.4, 10.358, 7.64E+5, 5.56E-5 are all floats.
• The float data type can commonly store a value up to
1.7976931348623E+308 (platform dependent), and
have a maximum precision of 14 digits.
PHP has the following functions to check if the type of a
variable is float:
 is_float()
 is_double() - alias of is_float()
Example
Check if the type of a variable is float:
<?php
$x = 10.365;
var_dump(is_float($x));
?>
PHP Infinity
• A numeric value that is larger than PHP_FLOAT_MAX is considered infinite.
• PHP has the following functions to check if a numeric value is finite or infinite:
 is_finite()
 is_infinite()
• However, the PHP var_dump() function returns the data type and
value:
Example
Check if a numeric value is finite or infinite:
<?php
$x = 1.9e411;
var_dump($x);
?>
PHP-NaN
• NaN stands for Not a Number.
• NaN is used for impossible mathematical operations.
• PHP has the following functions to check if a value is not a number:
 is_nan()
• Here, the PHP var_dump() function returns the data type and value:
Example
• Invalid calculation will return a NaN value:
<?php
$x = acos(8);
var_dump($x);
?>
PHP String
• A string is a sequence of characters, like "Hello world!".
• A string can be any text inside quotes. We can use single or double
quotes:
Example
<?php
$x = "Hello world!";
$y = 'Hello world!';
echo $x;
echo "<br>";
echo $y;
?>
PHP Integer
• An integer data type is a non-decimal number between
-2,147,483,648 and 2,147,483,647.
• Rules for integers:
 An integer must have at least one digit
 An integer must not have a decimal point
 An integer can be either positive or negative
 Integers can be specified in: decimal (base 10),
hexadecimal (base 16), octal (base 8), or binary (base
2) notation
Example
<?php
$x = 5985;
var_dump($x);
?>
• Note: The PHP var_dump() function returns the data
type and value:
PHP Float
• A float (floating point number) is a number with a
decimal point or a number in exponential form.
• Here $x is a float. The PHP var_dump() function returns
the data type and value:
Example
<?php
$x = 10.365;
var_dump($x);
?>
PHP Boolean
• A Boolean represents two possible states:
TRUE or FALSE.
$x = true;
$y = false;
• Booleans are often used in conditional
testing
PHP Array
• An array stores multiple values in one single variable.
• In the following example $days is an array. The PHP
var_dump() function returns the data type and value:
Example
<?php
$days = array(“Sunday",“Monday”,"Tuesday");
var_dump($days);
?>
PHP Object
• An object is a data type which stores data and
information on how to process that data.
• In PHP, an object must be explicitly declared.
• To declare a class of object, the keyword class is used.
A class is a structure that can contain properties and
methods:
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.
• Tip: If a variable is created without a value, it is
automatically assigned a value of NULL.
• Variables can also be emptied by setting the value to
NULL:
Example
<?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
PHP Resource
• The special resource type is not an actual data type. It
is the storing of a reference to functions and resources
external to PHP.
• A common example of using the resource data type is a
database call.
Summary
• PHP was created by Rasmus Lerdorf in
1994 but appeared in the market in 1995. PHP
7.4.0 is the latest version of PHP, which was
released on 28 November.
• Some important points need to be noticed about
PHP are as followed.
• PHP stands for Hypertext Preprocessor.
• PHP is an interpreted language, i.e., there is no need
for compilation.
• PHP is faster than other scripting languages, for
example, ASP and JSP.
• PHP is a server-side scripting language, which is
used to manage the dynamic content of the
website.
• PHP can be embedded into HTML.
• PHP is an object-oriented language.
• PHP is an open-source scripting language.
• PHP is simple and easy to learn language.

Más contenido relacionado

La actualidad más candente (20)

Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Introduction to-php
Introduction to-phpIntroduction to-php
Introduction to-php
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Ph pbasics
Ph pbasicsPh pbasics
Ph pbasics
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
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
 
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
 
Php intro
Php introPhp intro
Php intro
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Php introduction and configuration
Php introduction and configurationPhp introduction and configuration
Php introduction and configuration
 
Php basics
Php basicsPhp basics
Php basics
 
Php tutorial
Php  tutorialPhp  tutorial
Php tutorial
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
php
phpphp
php
 
Welcome to computer programmer 2
Welcome to computer programmer 2Welcome to computer programmer 2
Welcome to computer programmer 2
 

Similar a Php unit i (20)

Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
 
php Chapter 1.pptx
php Chapter 1.pptxphp Chapter 1.pptx
php Chapter 1.pptx
 
1. introduction to php and variable
1. introduction to php and variable1. introduction to php and variable
1. introduction to php and variable
 
Introduction to PHP.pptx
Introduction to PHP.pptxIntroduction to PHP.pptx
Introduction to PHP.pptx
 
php basic part one
php basic part onephp basic part one
php basic part one
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
Php unit i
Php unit i Php unit i
Php unit i
 
Prersentation
PrersentationPrersentation
Prersentation
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
Php tutorialw3schools
Php tutorialw3schoolsPhp tutorialw3schools
Php tutorialw3schools
 
PHP
PHPPHP
PHP
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
PHP.docx
PHP.docxPHP.docx
PHP.docx
 
Php
PhpPhp
Php
 
PHP tutorial | ptutorial
PHP tutorial | ptutorialPHP tutorial | ptutorial
PHP tutorial | ptutorial
 
Php
PhpPhp
Php
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 

Último

21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 

Último (20)

21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

Php unit i

  • 2. PHP-Introduction • PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. • PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP. • PHP 7 is the latest stable release.
  • 3. Why to learn PHP? • Some of the key advantages of learning PHP:  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.
  • 4.  PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. PHP4 added support for Java and distributed object architectures (COM and CORBA), making n- tier development a possibility for the first time.  PHP Syntax is C-Like.
  • 5. Characteristics of PHP • Five important characteristics make PHP's practical nature possible 1. Simplicity 2. Efficiency 3. Security 4. Flexibility 5. Familiarity
  • 6. Applications of PHP • PHP is one of the most widely used language over the web.  PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close them.  PHP can handle forms, i.e. gather data from files, save data to a file, through email you can send data, return data to the user.  You add, delete, modify elements within your database through PHP.  Access cookies variables and set cookies.  Using PHP, you can restrict users to access some pages of your website.  It can encrypt data.
  • 7. PHP - Environment • In order to develop and run PHP Web pages three vital components need to be installed on your computer system.  Web Server − PHP will work with virtually all Web Server software, including Microsoft's Internet Information Server (IIS) but then most often used is freely available Apache Server. Download Apache for free here − https://httpd.apache.org/download.cgi  Database − PHP will work with virtually all database software, including Oracle and Sybase but most commonly used is freely available MySQL database. Download MySQL for free here − https://www.mysql.com/downloads/  PHP Parser − In order to process PHP script instructions a parser must be installed to generate HTML output that can be sent to the Web Browser.
  • 8. History of PHP PHP was originally created by a developer named Rasmus Lerdorf.
  • 9. Features/Advantages of PHP 1.Performance 2.Portability(Platform Independent) 3.Ease Of Use(Familiarity with syntax) 4.Open Source 5.Embedded 6.Third-Party Application Support(Database Support) 7. A helpful PHP Community Support
  • 10. • Error Reporting • Loosely Typed Language • Web servers Support • Security • Control
  • 11. PHP Installation • To start using PHP, • Find a web host with PHP and MySQL support • Install a web server on your own PC, and then install PHP and MySQL
  • 12. Set Up PHP on Your Own PC • However, if your server does not support PHP, you must: 1. install a web server 2. install PHP 3. install a database, such as MySQL
  • 13. PHP Software Requirement PHP Server • The PHP Community Provides Some types of Software Server solution under The GNU (General Public License). • These are the following: 1.WAMP Server 2.LAMP Server 3.MAMP Server 4.XAMPP Server
  • 14.
  • 15. • WAMP for Windows • LAMP for Linux • MAMP for Mac • SAMP for Solaris • FAMP for FreeBSD • XAMPP (Cross, Apache, MySQL, PHP, Perl) for Cross Platform: It includes some other components too such as FileZilla, OpenSSL, Webalizer, Mercury Mail, etc.
  • 16. PHP Syntax • A PHP script is executed on the server, and the plain HTML result is sent back to the browser. • 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
  • 18. Example <!DOCTYPE html> <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html> Note: PHP statements end with a semicolon (;)
  • 19. The PHP command ‘echo’ is used to output the parameters passed to it ◦ The typical usage for this is to send data to the client’s web-browser Syntax ◦ void echo (string arg1 [, string argn...]) ◦ In practice, arguments are not passed in parentheses since echo is a language construct rather than an actual function Echo
  • 20. • PHP echo statement can be used to print the string, multi-line strings, escaping characters, variable, array, etc. • Some important points about the echo statement are: • echo is a statement, which is used to display the output. • echo can be used with or without parentheses: echo(), and echo. • echo does not return any value. • We can pass multiple strings separated by a comma (,) in echo. • echo is faster than the print statement.
  • 21. PHP echo: printing string <?php echo "Hello by PHP echo"; ?> Output: Hello by PHP echo
  • 22. PHP echo: printing multi line string <?php echo "Hello by PHP echo this is multi line text printed by PHP echo statement "; ?> Output: Hello by PHP echo this is multi line text printed by PHP echo statement
  • 23. PHP echo: printing escaping characters <?php echo "Hello escape "sequence" chara cters"; ?> Output: Hello escape "sequence" characters
  • 24. PHP echo: printing variable value <?php $msg="Hello JavaTpoint PHP"; echo "Message is: $msg"; ?> Output: Message is: Hello JavaTpoint PHP
  • 25. PHP echo and print statements • More or less same. Both are used to display data. But differences are small: 1. echo has no return value while print has a return value of 1 so it can be used in expressions. 2. echo can take multiple parameters while print can take one argument. 3. echo is marginally faster than print
  • 26. The PHP print Statement The print statement can be used with or without parentheses: print or print(). Display Text The following example shows how to output text with the print command (Notice that the text can contain HTML markup):
  • 27. Example <?php print "<h2>PHP is easy!</h2>"; print "Hello world!<br>"; print “Have a nice day!"; ?>
  • 28. Display Variables The following example shows how to output text and variables with the print statement: Example <?php $txt1 = “Hello"; $txt2 = “PHP"; $x = 5; $y = 4; print "<h2>" . $txt1 . "</h2>"; print “Welcome to " . $txt2 . "<br>"; print $x + $y; ?>
  • 29. PHP Case Sensitivity • In PHP, keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are not case-sensitive. • In the example below, all three echo statements below are equal and legal. • <!DOCTYPE html> <html> <body> <?php ECHO "Hello World!<br>"; echo "Hello World!<br>"; EcHo "Hello World!<br>"; ?> </body> </html> • Note: All three echo statements are equal and valid
  • 30. Example for case sensitive <!DOCTYPE html> <html> <body> <?php $color = "red"; echo "My car is " . $color . "<br>"; echo "My house is " . $COLOR . "<br>"; echo "My boat is " . $coLOR . "<br>"; ?> </body> </html> • Note: Here $color, $COLOR, and $coLOR are treated as three different variables . First statement is true.
  • 31. PHP Comments • A comment in PHP code is a line that is not executed as a part of the program. Its only purpose is to be read by someone who is looking at the code. • Comments can be used to:  Let others understand our code  Remind yourself of what you did - Most programmers have experienced coming back to their own work a year or two years later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code.
  • 32. PHP supports several ways of commenting: • Syntax for single-line comments <!DOCTYPE html> <html> <body> <?php // This is a single-line comment # This is also a single-line comment ?> </body> </html>
  • 33. • Syntax for multiple-line comments: <!DOCTYPE html> <html> <body> <?php /* This is a multiple-lines comment block that spans over multiple lines */ ?> </body> </html>
  • 34. PHP Variables • Variables are "containers" for storing information. Creating (Declaring) PHP Variables Example <?php $txt = "Hello world!"; $x = 5; $y = 10.5; ?>
  • 35. PHP Variables A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). 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) •Note: Remember that PHP variable names are case- sensitive!
  • 36. Output Variables • The PHP echo statement is often used to output data to the screen. • The following example will show how to output text and a variable: Example 1 <?php $txt = “PHP"; echo "I like $txt!"; ?>
  • 37. Example 2 <?php $txt = “PHP"; echo "I like " . $txt . "!"; ?> Note: The above example will produce the same output as the previous one.
  • 38. Example 3 <?php $x = 5; $y = 4; echo $x + $y; ?>
  • 39. PHP Variables Scope • In PHP, variables can be declared anywhere in the script • The scope of a variable is the part of the script where the variable can be referenced/used. • PHP has three different variable scopes: 1. local 2. global 3. static
  • 40. Global and Local Scope • A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function Example - Variable with global scope <?php $x = 5; // global scope function display() { // using x inside this function will generate an error echo "<p>Variable x inside function is: $x</p>"; } display(); echo "<p>Variable x outside function is: $x</p>"; ?>
  • 41. • A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function Example Variable with local scope: <?php function display() { $x = 5; // local scope echo "<p>Variable x inside function is: $x</p>"; } display(); // using x outside the function will generate an error echo "<p>Variable x outside function is: $x</p>"; ?>
  • 42. PHP The static Keyword • Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job. • So declare the variable as static <?php function display() { static $x = 0; echo $x; $x++; } display(); display(); display(); ?>
  • 43. The global keyword is used to access a global variable from within a function. To do this, use the global keyword before the variables (inside the function): PHP The global Keyword
  • 44. Example <?php $x = 5; $y = 10; function add() { global $x, $y; $y = $x + $y; } add(); echo $y; // outputs 15 ?>
  • 45. GLOBALS • PHP also stores all global variables in an array called $GLOBALS[index]. • The index holds the name of the variable. This array is also accessible from within functions and can be used to update global variables directly. The example above can be rewritten like this:
  • 46. Example <?php $x = 5; $y = 10; function add() { $GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y']; } add(); echo $y; // outputs 15 ?>
  • 47. PHP Data Types • Variables can store data of different types, and different data types can do different things. PHP supports the following data types: 1. String 2. Integer 3. Float (floating point numbers - also called double) 4. Boolean 5. Array 6. Object 7. NULL 8. Resource
  • 48. PHP Numbers PHP provides automatic data type conversion. So, if you assign an integer value to a variable, the type of that variable will automatically be an integer. Then, if you assign a string to the same variable, the type will change to a string. Example: $x=12; $x=‘Hello’;
  • 49. PHP Integers • An integer is a number without any decimal part. • Example: 2, 256, -256, 10358, -179567 are all integers. • So, an integer data type is a non-decimal number between -2147483648 and 2147483647. • Here are some rules for integers:  An integer must have at least one digit  An integer must not have a decimal point  An integer can be either positive or negative  Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based - prefixed with 0x) or octal (8-based - prefixed with 0)
  • 50. • PHP has the following functions to check if the type of a variable is integer:  is_int()  is_integer() - alias of is_int()  is_long() - alias of is_int() Check if the type of a variable is integer: <?php $x = 5985; var_dump(is_int($x)); $x = 59.85; var_dump(is_int($x)); ?>
  • 51. PHP Float • A float is a number with a decimal point or a number in exponential form. • 2.0, 256.4, 10.358, 7.64E+5, 5.56E-5 are all floats. • The float data type can commonly store a value up to 1.7976931348623E+308 (platform dependent), and have a maximum precision of 14 digits. PHP has the following functions to check if the type of a variable is float:  is_float()  is_double() - alias of is_float()
  • 52. Example Check if the type of a variable is float: <?php $x = 10.365; var_dump(is_float($x)); ?>
  • 53. PHP Infinity • A numeric value that is larger than PHP_FLOAT_MAX is considered infinite. • PHP has the following functions to check if a numeric value is finite or infinite:  is_finite()  is_infinite() • However, the PHP var_dump() function returns the data type and value: Example Check if a numeric value is finite or infinite: <?php $x = 1.9e411; var_dump($x); ?>
  • 54. PHP-NaN • NaN stands for Not a Number. • NaN is used for impossible mathematical operations. • PHP has the following functions to check if a value is not a number:  is_nan() • Here, the PHP var_dump() function returns the data type and value: Example • Invalid calculation will return a NaN value: <?php $x = acos(8); var_dump($x); ?>
  • 55. PHP String • A string is a sequence of characters, like "Hello world!". • A string can be any text inside quotes. We can use single or double quotes: Example <?php $x = "Hello world!"; $y = 'Hello world!'; echo $x; echo "<br>"; echo $y; ?>
  • 56. PHP Integer • An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647. • Rules for integers:  An integer must have at least one digit  An integer must not have a decimal point  An integer can be either positive or negative  Integers can be specified in: decimal (base 10), hexadecimal (base 16), octal (base 8), or binary (base 2) notation
  • 57. Example <?php $x = 5985; var_dump($x); ?> • Note: The PHP var_dump() function returns the data type and value:
  • 58. PHP Float • A float (floating point number) is a number with a decimal point or a number in exponential form. • Here $x is a float. The PHP var_dump() function returns the data type and value: Example <?php $x = 10.365; var_dump($x); ?>
  • 59. PHP Boolean • A Boolean represents two possible states: TRUE or FALSE. $x = true; $y = false; • Booleans are often used in conditional testing
  • 60. PHP Array • An array stores multiple values in one single variable. • In the following example $days is an array. The PHP var_dump() function returns the data type and value: Example <?php $days = array(“Sunday",“Monday”,"Tuesday"); var_dump($days); ?>
  • 61. PHP Object • An object is a data type which stores data and information on how to process that data. • In PHP, an object must be explicitly declared. • To declare a class of object, the keyword class is used. A class is a structure that can contain properties and methods:
  • 62. 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. • Tip: If a variable is created without a value, it is automatically assigned a value of NULL. • Variables can also be emptied by setting the value to NULL:
  • 63. Example <?php $x = "Hello world!"; $x = null; var_dump($x); ?>
  • 64. PHP Resource • The special resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP. • A common example of using the resource data type is a database call.
  • 65. Summary • PHP was created by Rasmus Lerdorf in 1994 but appeared in the market in 1995. PHP 7.4.0 is the latest version of PHP, which was released on 28 November. • Some important points need to be noticed about PHP are as followed. • PHP stands for Hypertext Preprocessor. • PHP is an interpreted language, i.e., there is no need for compilation.
  • 66. • PHP is faster than other scripting languages, for example, ASP and JSP. • PHP is a server-side scripting language, which is used to manage the dynamic content of the website. • PHP can be embedded into HTML. • PHP is an object-oriented language. • PHP is an open-source scripting language. • PHP is simple and easy to learn language.