SlideShare ist ein Scribd-Unternehmen logo
1 von 43
PHP
V SEM BCA
What is PHP?
• PHP stands for Hypertext Pre-Processor. PHP is a scripting language used to
develop static and dynamic webpages and web applications. Here are a few
important things you must know about PHP:
• PHP is one of the most widely used server-side scripting language for web
development. Popular websites like Facebook, Yahoo, Wikipedia etc., are
developed using PHP.
1.PHP is an Interpreted language; hence it doesn't need a compiler.
2.To run and execute PHP code, we need a Web server on which PHP must be
installed.
3.PHP is a server-side scripting language, which means that PHP is executed on the
server and the result is sent to the browser in plain HTML.
4.PHP is open source and free.
Features of PHP
1.PHP is open source and free, hence you can freely download, install and start developing
using it.
2.PHP has a very simple and easy to understand syntax, hence the learning curve is
smaller as compared to other scripting languages like JSP, ASP etc.
3.PHP is cross platform; hence you can easily develop and move/deploy your PHP
code/project to almost all the major operating systems like Windows, Linux, Mac OSX
etc.
4.All the popular web hosting services support PHP. Also, the web hosting plans for PHP
are generally the amongst the cheapest plans because of its popularity.
5.Popular Content Management Systems like Joomla, Drupal etc. are developed in PHP.
6.With PHP, you can create static and dynamic webpages, perform file handling operations,
send emails, access and modify browser cookies, and almost everything else that you
might want to implement in your web project.
7.PHP is fast as compared to other scripting languages like JSP and ASP.
8.PHP has in-built support for MySQL, which is one of the most widely used Database
management system.
Uses of PHP
1.It can be used to create Web applications like Social Networks (Facebook,
Digg), Blogs (WordPress, Joomla), eCommerce websites (OpenCart, Magento
etc.) etc.
2.Command Line Scripting. You can write PHP scripts to perform different
operations on any machine, all you need is a PHP parser for this.
3.Create Facebook applications and easily integrate Facebook plugins in your
website, using Facebook's PHP SDK.
4.Sending Emails or building email applications because PHP provides with a
robust email sending function.
5.WordPress is one of the most used blogging (CMS) platforms in the World, and if
you know PHP, you can try a hand in WordPress plugin development.
History of PHP
• Originally (it is believed) the letters stood for Personal Home Page. The first work
was done by Rasmus Lerdorf and dates back to about 1994. Lerdorf originally
used it for his personal page – specifically to track visitors. Soon, a lot of
additional functions were added. It took a few years, though, for it to become a
language and not just a set of tools.
• The code was released in the mid-1990s. Israel’s Andi Gutmans and Zeev Suraski
did a major overhaul in 1997 with the goal of using PHP to run an eCommerce
site. Their version, termed PHP 3.0, had more of the features we expect and see
today.
• The same duo later created Version 4.0. 2004 saw another major revision, PHP
5.0. Although there has not yet been a 6.0, there have been significant
improvements since 5.0, including the removal of several things that had caused
instability or potential security breaches.
Basic PHP syntax
• A PHP script can be placed anywhere in the document.
• A PHP script :
• starts with <?php and ends with ?>:
• The default file extension for PHP files is ".php".
• A PHP file normally contains HTML tags, and some PHP scripting code.
• PHP statement ends with semi colon (;).
• In PHP, keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-
defined functions are not case-sensitive.
• In PHP variables are case sensitive.
<?php
// PHP code goes here
?>
Why use PHP along with HTML
• PHP allows dynamic web page generation, which is not possible by using just
HTML. Thus by using PHP script along with HTML in a PHP file, the web
developers can generate dynamic web pages. The use of PHP also allows access to
various databases.
• PHP is used for server-side programming which will interact with databases to
retrieve information, storing, email sending, and provides content to HTML pages
to display on the screen.
Example Program
• <!DOCTYPE html>
<html>
<body>
<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>
</body>
</html>
PHP Form Handling
• The PHP superglobals $_GET and $_POST are used to collect form-data.
• <html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
• When the user fills out the form above and clicks the submit button, the form data
is sent for processing to a PHP file named "welcome.php". The form data is sent
with the HTTP POST method.
• $_GET retrieves variables from the querystring, or your URL.
• $_POST retrieves variables from a POST method, such as (generally) forms.
• $_POST is an associative array of variables passed to the current script via the
HTTP POST method when using application/x-www-form-urlencoded or
multipart/form-data as the HTTP Content-Type in the request. You can use when
you are sending large data to server or if you have sensitive information like
passwords, credit card details etc.
• $_GET is an associative array of variables passed to the current script via the
URL parameters. you can use when there is small amount of data, it is mostly used
in pagination, page number is shown in the url and you can easily get the page
number from URL using $_GET.
Embedding PHP and HTML
• Step 1: Firstly, we have to type the Html code in any text editor or open the
existing Html file in the text editor in which we want to use the PHP.
• Step 2: Now, we have to place the cursor in any tag of the <body> tag where we
want to add the code of PHP. And, then we have to type the start and end tag of
PHP.
• Step 3: After then, we have to type the code of PHP between the tags of PHP.
• Step 4: When we successfully add the PHP code, then we have to save the Html
file and then run the file in the browser.
How PHP code is parsed
• So you have a file, and in that file you have some HTML and some PHP code.
This is how it all works, assuming a PHP document with an extension of .php.
• The web browser requests a document with a .php extension.
• The web server says, "Hey! Someone wants a PHP file, which means this is a
file that needs to be parsed," and sends the request on to the PHP parser.
• The PHP parser finds the requested file and scans it for PHP code.
• When the PHP parser finds PHP code, it executes that code and places the
resulting output (if any) into the place in the file formerly occupied by the code.
• This new output file is sent back to the web server.
• The web server sends it along to the web browser.
• The web browser displays the output.
• Because the PHP code is parsed on the server, this method of code execution
is called server-side code.
Datatypes in PHP
• Data Types define the type of data a variable can store. PHP allows eight different
types of data types. There are pre-defined, user-defined, and special data types.
The predefined data types are:
• Boolean
• Integer
• Double
• String
The user-defined (compound) data types are:
• Array
• Objects
The special data types are:
• NULL
• resource
• The first five are called simple data types and the last three are compound data types:
• 1. Integer: Integers hold only whole numbers including positive and negative numbers,
i.e., numbers without fractional part or decimal point. They can be decimal (base 10),
octal (base 8), or hexadecimal (base 16). The default base is decimal (base 10). The octal
integers can be declared with leading 0 and the hexadecimal can be declared with leading
0x.
• // decimal base integers
• $deci1 = 50;
• $deci2 = 654;
• // octal base integers
• $octal1 = 07;
• // hexadecimal base integers
• $octal = 0x45;
• $sum = $deci1 + $deci2;
• echo $sum;
• echo "nn";
• //returns data type and value
• var_dump($sum)
• ?>
• 2. Double: Can hold numbers containing fractional or decimal parts including
positive and negative numbers or a number in exponential form. By default, the
variables add a minimum number of decimal places. The Double data type is the
same as a float as floating-point numbers or real numbers.
• <?php
• $val1 = 50.85;
• $val2 = 654.26;
• $sum = $val1 + $val2;
• echo $sum;
• echo "nn";
• //returns data type and value
• var_dump($sum)
• ?>
• 3. String: Hold letters or any alphabets, even numbers are included. These are
written within double quotes during declaration.
• <?php
• $name = “Computer";
• echo "The name of the Geek is $name n";
• echo "nn";
• //returns data type, size and value
• var_dump($name)
• ?>
• 4. Boolean: Boolean data types are used in conditional testing. Hold only two
values, either TRUE(1) or FALSE(0). Successful events will return true and
unsuccessful events return false. NULL type values are also treated as false in
Boolean. Apart from NULL, 0 is also considered false in boolean. If a string is
empty then it is also considered false in boolean data type.
• <?php
• if(TRUE)
• echo "This condition is TRUE";
• if(FALSE)
• echo "This condition is not TRUE";
• ?>
• 5. Array: Array is a compound data type that can store multiple values of the same
data type. Below is an example of an array of integers. It combines a series of data
that are related together.
• <?php
• $intArray = array( 10, 20 , 30);
• echo "First Element: $intArray[0]n";
• echo "Second Element: $intArray[1]n";
• echo "Third Element: $intArray[2]nn";
• //returns data type and value
• var_dump($intArray);
• ?>
• 6. Objects: Objects are defined as instances of user-defined classes that can hold both values and
functions and information for data processing specific to the class. When the objects are created, they
inherit all the properties and behaviours from the class, having different values for all the properties.
• Objects are explicitly declared and created from the new keyword.
• <?php
• class gfg {
• var $message
• function gfg($message) {
• $this->message = $message;
• }
• function msg() {
• return "This is an example of " . $this->message . "!";
• }
• }
• // instantiating a object
• $newObj = new gfg("Object Data Type");
• echo $newObj -> msg();
• ?>
• 7. NULL: These are special types of variables that can hold only one value i.e.,
NULL. We follow the convention of writing it in capital form, but it’s case-
sensitive. If a variable is created without a value or no value, it is automatically
assigned a value of NULL. It is written in capital letters.
• <?php
• $nm = NULL;
• echo $nm; // this will return no output
• // return data type
• var_dump($nm);
• ?>
• 8. Resources: Resources in PHP are not an exact data type. These are basically
used to store references to some function call or to external PHP resources. For
example, consider a database call. This is an external resource. Resource variables
hold special handles for files and database connections.
Operators in PHP
• Operators are used to perform operations on variables and values.
• PHP divides the operators in the following groups:
• Arithmetic operators
• Assignment operators
• Comparison operators
• Increment/Decrement operators
• Logical operators
• String operators
• Array operators
• Conditional assignment operators
Arithmetic Operators
• The PHP arithmetic operators are used with numeric values to perform common
arithmetical operations, such as addition, subtraction, multiplication etc.
Assignment Operators
• The PHP assignment operators are used with numeric values to write a value to a
variable.
• The basic assignment operator in PHP is "=". It means that the left operand gets
set to the value of the assignment expression on the right.
Comparison Operators
• The PHP comparison operators are used to compare two values (number or
string):
Increment/Decrement Operators
• The PHP increment operators are used to increment a variable's value.
• The PHP decrement operators are used to decrement a variable's value.
Logical Operators
• The PHP logical operators are used to combine conditional statements.
String Operators
• PHP has two operators that are specially designed for strings.
•
Array Operators
• The PHP array operators are used to compare arrays.
Conditional Assignment Operators
• The PHP conditional assignment operators are used to set a value depending on
conditions:
PHP variables
• Creating (Declaring) PHP Variables
• In PHP, a variable starts with the $ sign, followed by the name of the variable:
• <?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
• After the execution of the statements above, the variable $txt will hold the value
Hello world!, the variable $x will hold the value 5, and the variable $y will hold
the value 10.5.
Rules for assigning name for 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)
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:
• <?php
• $txt = “google.com";
• echo "I love $txt!";
• ?>
Print
• The print statement can be used with or without parentheses: print or print().
• The differences are small: echo has no return value while print has a return value
of 1 so it can be used in expressions. echo can take multiple parameters (although
such usage is rare) while print can take one argument. echo is marginally faster
than print.
• <?php
• print "<h2>PHP is Fun!</h2>";
• print "Hello world!<br>";
• print "I'm about to learn PHP!";
• ?>
Static And Global Variables
• 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:
• local
• global
• static
Global and Local Scope
• A variable declared outside a function has a GLOBAL SCOPE and can only
be accessed outside a function.
• <?php
• $x = 5; // global scope
• function myTest() {
• // using x inside this function will generate an error
• echo "<p>Variable x inside function is: $x</p>";
• }
• myTest();
• 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.
• <?php
• function myTest() {
• $x = 5; // local scope
• echo "<p>Variable x inside function is: $x</p>";
• }
• myTest();
• // using x outside the function will generate an error
• echo "<p>Variable x outside function is: $x</p>";
• ?>
PHP The global Keyword
• The global keyword is used to access a global variable from within the function.
• We have to use global keyword before the variables (inside the function).
• <?php
$x = 5;
$y = 10;
function myTest() {
global $x, $y;
$y = $x + $y;
}
myTest();
echo $y; // outputs 15
?>
• 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 the functions and
can be used to update global variables directly.
• <?php
• $x = 5;
• $y = 10;
• function myTest() {
• $GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
• }
• myTest();
• echo $y; // outputs 15
• ?>
Static Keyword
• 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.
• To do this, use the static keyword when you first declare the variable.
• <?php
• function myTest() {
• static $x = 0;
• echo $x;
• $x++;
• }
• myTest();
• myTest();
• myTest();
• ?>
Comments in PHP
• 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 your code
• Remind yourself of what you did - Most programmers have experienced coming back to their own work
a year or two 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:
• Single Line commenting
• <!DOCTYPE html>
• <html>
• <body>
• <?php
• // This is a single-line comment
• # This is also a single-line comment
• ?>
• </body>
• </html>
• Multiple Line Comments
• <!DOCTYPE html>
• <html>
• <body>
• <?php
• /*
• This is a multiple-lines comment block
• that spans over multiple
• lines
• */
• ?>
• </body>
• </html>
• Using comments to leave out parts of the code.
• <!DOCTYPE html>
<html>
<body>
<?php
// You can also use comments to leave out parts of a code line
$x = 5 /* + 15 */ + 5;
echo $x;
?>
</body>
</html>

Weitere ähnliche Inhalte

Ähnlich wie Introduction to PHP.pptx

Ähnlich wie Introduction to PHP.pptx (20)

php basic part one
php basic part onephp basic part one
php basic part one
 
Introduction to php
Introduction  to  phpIntroduction  to  php
Introduction to php
 
web Based Application Devlopment using PHP
web Based Application Devlopment using PHPweb Based Application Devlopment using PHP
web Based Application Devlopment using PHP
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
Php tutorialw3schools
Php tutorialw3schoolsPhp tutorialw3schools
Php tutorialw3schools
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
 
Php Basics
Php BasicsPhp Basics
Php Basics
 
PHP ITCS 323
PHP ITCS 323PHP ITCS 323
PHP ITCS 323
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
php Chapter 1.pptx
php Chapter 1.pptxphp Chapter 1.pptx
php Chapter 1.pptx
 
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
 
Php1
Php1Php1
Php1
 
PHP language presentation
PHP language presentationPHP language presentation
PHP language presentation
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_master
 
Php1
Php1Php1
Php1
 
Php1
Php1Php1
Php1
 
Php
PhpPhp
Php
 

Mehr von SherinRappai

Extensible markup language ppt as part of Internet Technology
Extensible markup language ppt as part of Internet TechnologyExtensible markup language ppt as part of Internet Technology
Extensible markup language ppt as part of Internet TechnologySherinRappai
 
Java script ppt from students in internet technology
Java script ppt from students in internet technologyJava script ppt from students in internet technology
Java script ppt from students in internet technologySherinRappai
 
Building Competency and Career in the Open Source World
Building Competency and Career in the Open Source WorldBuilding Competency and Career in the Open Source World
Building Competency and Career in the Open Source WorldSherinRappai
 
How to Build a Career in Open Source.pptx
How to Build a Career in Open Source.pptxHow to Build a Career in Open Source.pptx
How to Build a Career in Open Source.pptxSherinRappai
 
Issues in Knowledge representation for students
Issues in Knowledge representation for studentsIssues in Knowledge representation for students
Issues in Knowledge representation for studentsSherinRappai
 
A* algorithm of Artificial Intelligence for BCA students
A* algorithm of Artificial Intelligence for BCA studentsA* algorithm of Artificial Intelligence for BCA students
A* algorithm of Artificial Intelligence for BCA studentsSherinRappai
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxSherinRappai
 
neuralnetwork.pptx
neuralnetwork.pptxneuralnetwork.pptx
neuralnetwork.pptxSherinRappai
 
Rendering Algorithms.pptx
Rendering Algorithms.pptxRendering Algorithms.pptx
Rendering Algorithms.pptxSherinRappai
 
Introduction to Multimedia.pptx
Introduction to Multimedia.pptxIntroduction to Multimedia.pptx
Introduction to Multimedia.pptxSherinRappai
 
Working with data.pptx
Working with data.pptxWorking with data.pptx
Working with data.pptxSherinRappai
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptxSherinRappai
 
Introduction to DBMS.pptx
Introduction to DBMS.pptxIntroduction to DBMS.pptx
Introduction to DBMS.pptxSherinRappai
 
Input_Output_Organization.pptx
Input_Output_Organization.pptxInput_Output_Organization.pptx
Input_Output_Organization.pptxSherinRappai
 

Mehr von SherinRappai (20)

Extensible markup language ppt as part of Internet Technology
Extensible markup language ppt as part of Internet TechnologyExtensible markup language ppt as part of Internet Technology
Extensible markup language ppt as part of Internet Technology
 
Java script ppt from students in internet technology
Java script ppt from students in internet technologyJava script ppt from students in internet technology
Java script ppt from students in internet technology
 
Building Competency and Career in the Open Source World
Building Competency and Career in the Open Source WorldBuilding Competency and Career in the Open Source World
Building Competency and Career in the Open Source World
 
How to Build a Career in Open Source.pptx
How to Build a Career in Open Source.pptxHow to Build a Career in Open Source.pptx
How to Build a Career in Open Source.pptx
 
Issues in Knowledge representation for students
Issues in Knowledge representation for studentsIssues in Knowledge representation for students
Issues in Knowledge representation for students
 
A* algorithm of Artificial Intelligence for BCA students
A* algorithm of Artificial Intelligence for BCA studentsA* algorithm of Artificial Intelligence for BCA students
A* algorithm of Artificial Intelligence for BCA students
 
Unit 2.pptx
Unit 2.pptxUnit 2.pptx
Unit 2.pptx
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
 
Clustering.pptx
Clustering.pptxClustering.pptx
Clustering.pptx
 
neuralnetwork.pptx
neuralnetwork.pptxneuralnetwork.pptx
neuralnetwork.pptx
 
Rendering Algorithms.pptx
Rendering Algorithms.pptxRendering Algorithms.pptx
Rendering Algorithms.pptx
 
Introduction to Multimedia.pptx
Introduction to Multimedia.pptxIntroduction to Multimedia.pptx
Introduction to Multimedia.pptx
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
system model.pptx
system model.pptxsystem model.pptx
system model.pptx
 
SE UNIT-1.pptx
SE UNIT-1.pptxSE UNIT-1.pptx
SE UNIT-1.pptx
 
Working with data.pptx
Working with data.pptxWorking with data.pptx
Working with data.pptx
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Introduction to DBMS.pptx
Introduction to DBMS.pptxIntroduction to DBMS.pptx
Introduction to DBMS.pptx
 
Input_Output_Organization.pptx
Input_Output_Organization.pptxInput_Output_Organization.pptx
Input_Output_Organization.pptx
 

Kürzlich hochgeladen

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Introduction to PHP.pptx

  • 2. What is PHP? • PHP stands for Hypertext Pre-Processor. PHP is a scripting language used to develop static and dynamic webpages and web applications. Here are a few important things you must know about PHP: • PHP is one of the most widely used server-side scripting language for web development. Popular websites like Facebook, Yahoo, Wikipedia etc., are developed using PHP. 1.PHP is an Interpreted language; hence it doesn't need a compiler. 2.To run and execute PHP code, we need a Web server on which PHP must be installed. 3.PHP is a server-side scripting language, which means that PHP is executed on the server and the result is sent to the browser in plain HTML. 4.PHP is open source and free.
  • 3. Features of PHP 1.PHP is open source and free, hence you can freely download, install and start developing using it. 2.PHP has a very simple and easy to understand syntax, hence the learning curve is smaller as compared to other scripting languages like JSP, ASP etc. 3.PHP is cross platform; hence you can easily develop and move/deploy your PHP code/project to almost all the major operating systems like Windows, Linux, Mac OSX etc. 4.All the popular web hosting services support PHP. Also, the web hosting plans for PHP are generally the amongst the cheapest plans because of its popularity. 5.Popular Content Management Systems like Joomla, Drupal etc. are developed in PHP. 6.With PHP, you can create static and dynamic webpages, perform file handling operations, send emails, access and modify browser cookies, and almost everything else that you might want to implement in your web project. 7.PHP is fast as compared to other scripting languages like JSP and ASP. 8.PHP has in-built support for MySQL, which is one of the most widely used Database management system.
  • 4. Uses of PHP 1.It can be used to create Web applications like Social Networks (Facebook, Digg), Blogs (WordPress, Joomla), eCommerce websites (OpenCart, Magento etc.) etc. 2.Command Line Scripting. You can write PHP scripts to perform different operations on any machine, all you need is a PHP parser for this. 3.Create Facebook applications and easily integrate Facebook plugins in your website, using Facebook's PHP SDK. 4.Sending Emails or building email applications because PHP provides with a robust email sending function. 5.WordPress is one of the most used blogging (CMS) platforms in the World, and if you know PHP, you can try a hand in WordPress plugin development.
  • 5. History of PHP • Originally (it is believed) the letters stood for Personal Home Page. The first work was done by Rasmus Lerdorf and dates back to about 1994. Lerdorf originally used it for his personal page – specifically to track visitors. Soon, a lot of additional functions were added. It took a few years, though, for it to become a language and not just a set of tools. • The code was released in the mid-1990s. Israel’s Andi Gutmans and Zeev Suraski did a major overhaul in 1997 with the goal of using PHP to run an eCommerce site. Their version, termed PHP 3.0, had more of the features we expect and see today. • The same duo later created Version 4.0. 2004 saw another major revision, PHP 5.0. Although there has not yet been a 6.0, there have been significant improvements since 5.0, including the removal of several things that had caused instability or potential security breaches.
  • 6. Basic PHP syntax • A PHP script can be placed anywhere in the document. • A PHP script : • starts with <?php and ends with ?>: • The default file extension for PHP files is ".php". • A PHP file normally contains HTML tags, and some PHP scripting code. • PHP statement ends with semi colon (;). • In PHP, keywords (e.g. if, else, while, echo, etc.), classes, functions, and user- defined functions are not case-sensitive. • In PHP variables are case sensitive. <?php // PHP code goes here ?>
  • 7. Why use PHP along with HTML • PHP allows dynamic web page generation, which is not possible by using just HTML. Thus by using PHP script along with HTML in a PHP file, the web developers can generate dynamic web pages. The use of PHP also allows access to various databases. • PHP is used for server-side programming which will interact with databases to retrieve information, storing, email sending, and provides content to HTML pages to display on the screen.
  • 8. Example Program • <!DOCTYPE html> <html> <body> <?php ECHO "Hello World!<br>"; echo "Hello World!<br>"; EcHo "Hello World!<br>"; ?> </body> </html>
  • 9. PHP Form Handling • The PHP superglobals $_GET and $_POST are used to collect form-data. • <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body> </html> • When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named "welcome.php". The form data is sent with the HTTP POST method. • $_GET retrieves variables from the querystring, or your URL. • $_POST retrieves variables from a POST method, such as (generally) forms.
  • 10. • $_POST is an associative array of variables passed to the current script via the HTTP POST method when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request. You can use when you are sending large data to server or if you have sensitive information like passwords, credit card details etc. • $_GET is an associative array of variables passed to the current script via the URL parameters. you can use when there is small amount of data, it is mostly used in pagination, page number is shown in the url and you can easily get the page number from URL using $_GET.
  • 11. Embedding PHP and HTML • Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to use the PHP. • Step 2: Now, we have to place the cursor in any tag of the <body> tag where we want to add the code of PHP. And, then we have to type the start and end tag of PHP. • Step 3: After then, we have to type the code of PHP between the tags of PHP. • Step 4: When we successfully add the PHP code, then we have to save the Html file and then run the file in the browser.
  • 12. How PHP code is parsed • So you have a file, and in that file you have some HTML and some PHP code. This is how it all works, assuming a PHP document with an extension of .php. • The web browser requests a document with a .php extension. • The web server says, "Hey! Someone wants a PHP file, which means this is a file that needs to be parsed," and sends the request on to the PHP parser. • The PHP parser finds the requested file and scans it for PHP code. • When the PHP parser finds PHP code, it executes that code and places the resulting output (if any) into the place in the file formerly occupied by the code. • This new output file is sent back to the web server. • The web server sends it along to the web browser. • The web browser displays the output. • Because the PHP code is parsed on the server, this method of code execution is called server-side code.
  • 13. Datatypes in PHP • Data Types define the type of data a variable can store. PHP allows eight different types of data types. There are pre-defined, user-defined, and special data types. The predefined data types are: • Boolean • Integer • Double • String The user-defined (compound) data types are: • Array • Objects The special data types are: • NULL • resource
  • 14. • The first five are called simple data types and the last three are compound data types: • 1. Integer: Integers hold only whole numbers including positive and negative numbers, i.e., numbers without fractional part or decimal point. They can be decimal (base 10), octal (base 8), or hexadecimal (base 16). The default base is decimal (base 10). The octal integers can be declared with leading 0 and the hexadecimal can be declared with leading 0x. • // decimal base integers • $deci1 = 50; • $deci2 = 654; • // octal base integers • $octal1 = 07; • // hexadecimal base integers • $octal = 0x45; • $sum = $deci1 + $deci2; • echo $sum; • echo "nn"; • //returns data type and value • var_dump($sum) • ?>
  • 15. • 2. Double: Can hold numbers containing fractional or decimal parts including positive and negative numbers or a number in exponential form. By default, the variables add a minimum number of decimal places. The Double data type is the same as a float as floating-point numbers or real numbers. • <?php • $val1 = 50.85; • $val2 = 654.26; • $sum = $val1 + $val2; • echo $sum; • echo "nn"; • //returns data type and value • var_dump($sum) • ?>
  • 16. • 3. String: Hold letters or any alphabets, even numbers are included. These are written within double quotes during declaration. • <?php • $name = “Computer"; • echo "The name of the Geek is $name n"; • echo "nn"; • //returns data type, size and value • var_dump($name) • ?>
  • 17. • 4. Boolean: Boolean data types are used in conditional testing. Hold only two values, either TRUE(1) or FALSE(0). Successful events will return true and unsuccessful events return false. NULL type values are also treated as false in Boolean. Apart from NULL, 0 is also considered false in boolean. If a string is empty then it is also considered false in boolean data type. • <?php • if(TRUE) • echo "This condition is TRUE"; • if(FALSE) • echo "This condition is not TRUE"; • ?>
  • 18. • 5. Array: Array is a compound data type that can store multiple values of the same data type. Below is an example of an array of integers. It combines a series of data that are related together. • <?php • $intArray = array( 10, 20 , 30); • echo "First Element: $intArray[0]n"; • echo "Second Element: $intArray[1]n"; • echo "Third Element: $intArray[2]nn"; • //returns data type and value • var_dump($intArray); • ?>
  • 19. • 6. Objects: Objects are defined as instances of user-defined classes that can hold both values and functions and information for data processing specific to the class. When the objects are created, they inherit all the properties and behaviours from the class, having different values for all the properties. • Objects are explicitly declared and created from the new keyword. • <?php • class gfg { • var $message • function gfg($message) { • $this->message = $message; • } • function msg() { • return "This is an example of " . $this->message . "!"; • } • } • // instantiating a object • $newObj = new gfg("Object Data Type"); • echo $newObj -> msg(); • ?>
  • 20. • 7. NULL: These are special types of variables that can hold only one value i.e., NULL. We follow the convention of writing it in capital form, but it’s case- sensitive. If a variable is created without a value or no value, it is automatically assigned a value of NULL. It is written in capital letters. • <?php • $nm = NULL; • echo $nm; // this will return no output • // return data type • var_dump($nm); • ?>
  • 21. • 8. Resources: Resources in PHP are not an exact data type. These are basically used to store references to some function call or to external PHP resources. For example, consider a database call. This is an external resource. Resource variables hold special handles for files and database connections.
  • 22. Operators in PHP • Operators are used to perform operations on variables and values. • PHP divides the operators in the following groups: • Arithmetic operators • Assignment operators • Comparison operators • Increment/Decrement operators • Logical operators • String operators • Array operators • Conditional assignment operators
  • 23. Arithmetic Operators • The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.
  • 24. Assignment Operators • The PHP assignment operators are used with numeric values to write a value to a variable. • The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.
  • 25. Comparison Operators • The PHP comparison operators are used to compare two values (number or string):
  • 26. Increment/Decrement Operators • The PHP increment operators are used to increment a variable's value. • The PHP decrement operators are used to decrement a variable's value.
  • 27. Logical Operators • The PHP logical operators are used to combine conditional statements.
  • 28. String Operators • PHP has two operators that are specially designed for strings. •
  • 29. Array Operators • The PHP array operators are used to compare arrays.
  • 30. Conditional Assignment Operators • The PHP conditional assignment operators are used to set a value depending on conditions:
  • 31. PHP variables • Creating (Declaring) PHP Variables • In PHP, a variable starts with the $ sign, followed by the name of the variable: • <?php $txt = "Hello world!"; $x = 5; $y = 10.5; ?> • After the execution of the statements above, the variable $txt will hold the value Hello world!, the variable $x will hold the value 5, and the variable $y will hold the value 10.5.
  • 32. Rules for assigning name for 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)
  • 33. 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: • <?php • $txt = “google.com"; • echo "I love $txt!"; • ?>
  • 34. Print • The print statement can be used with or without parentheses: print or print(). • The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print. • <?php • print "<h2>PHP is Fun!</h2>"; • print "Hello world!<br>"; • print "I'm about to learn PHP!"; • ?>
  • 35. Static And Global Variables • 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: • local • global • static
  • 36. Global and Local Scope • A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function. • <?php • $x = 5; // global scope • function myTest() { • // using x inside this function will generate an error • echo "<p>Variable x inside function is: $x</p>"; • } • myTest(); • echo "<p>Variable x outside function is: $x</p>"; • ?>
  • 37. • A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function. • <?php • function myTest() { • $x = 5; // local scope • echo "<p>Variable x inside function is: $x</p>"; • } • myTest(); • // using x outside the function will generate an error • echo "<p>Variable x outside function is: $x</p>"; • ?>
  • 38. PHP The global Keyword • The global keyword is used to access a global variable from within the function. • We have to use global keyword before the variables (inside the function). • <?php $x = 5; $y = 10; function myTest() { global $x, $y; $y = $x + $y; } myTest(); echo $y; // outputs 15 ?>
  • 39. • 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 the functions and can be used to update global variables directly. • <?php • $x = 5; • $y = 10; • function myTest() { • $GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y']; • } • myTest(); • echo $y; // outputs 15 • ?>
  • 40. Static Keyword • 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. • To do this, use the static keyword when you first declare the variable. • <?php • function myTest() { • static $x = 0; • echo $x; • $x++; • } • myTest(); • myTest(); • myTest(); • ?>
  • 41. Comments in PHP • 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 your code • Remind yourself of what you did - Most programmers have experienced coming back to their own work a year or two 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: • Single Line commenting • <!DOCTYPE html> • <html> • <body> • <?php • // This is a single-line comment • # This is also a single-line comment • ?> • </body> • </html>
  • 42. • Multiple Line Comments • <!DOCTYPE html> • <html> • <body> • <?php • /* • This is a multiple-lines comment block • that spans over multiple • lines • */ • ?> • </body> • </html>
  • 43. • Using comments to leave out parts of the code. • <!DOCTYPE html> <html> <body> <?php // You can also use comments to leave out parts of a code line $x = 5 /* + 15 */ + 5; echo $x; ?> </body> </html>

Hinweis der Redaktion

  1. An interpreted language is a programming language whose implementations execute instructions directly and freely, without previously compiling a program into machine-language instructions. Server-side scripting languages are programming languages developed especially for creating HTML pages (or Web pages) on the server side
  2. Web hosting is the activity of providing storage space for a website that is connected to the Internet. When you have a company that has space on servers and people buy space to store their websites so they can appear on the Internet,
  3. WordPress is a free and open-source content management system written in PHP and paired with a MySQL or MariaDB database with supported HTTPS.
  4. All HTML need to have a DOCTYPE declared. The DOCTYPE is not actually an element or HTML tag. It lets the browser know how the document should be interpreted, by indicating what version or standard of HTML (or other markup language) is being used.