SlideShare uma empresa Scribd logo
1 de 48
PHP (Hypertext Preprocessor)
-Gursharandeep kaur bajwa
(CTIEMT)
100220314317
IntroductionIntroduction

PHP is stands for ’Hypertext Preprocessor ’ used for making
dynamic web pages and interactive web pages.

PHP is server side scripting language intented to help web
developers build dynamic web pages.

PHP scripts are executed on the server.

PHP supports many databases (MySql ,Oracle,PostgreSQL,Generic
ODBC etc).

PHP was created by Rasmus Lerdrof in 1995.

PHP originally stood for ”PERSONAL HOME PAGE”

PHP is an Open Source software.

PHP is free to download and use.
PHP FilesPHP Files

PHP files can contain text, HTML Tags and scripts.

PHP files are returned to the browser as plain HTML

PHP files have a file extension of ”.php”.
EXECUTION OF PHP PAGE
“PHP is an HTML-embedded scripting language. Much of its syntax is
borrowed from C,Java & Perl with a couple of unique PHP-specific
features thrown in .The goal of the language is to allow web developers
to write dynamically generated pages quickly. ”
Brief History of PHPBrief History of PHP
PHP (PHP: Hypertext Preprocessor) was created by Rasmus Lerdorf
in 1994. It was initially developed for HTTP usage logging and server-
side form generation in Unix

PHP 2 (1995) transformed the language into a Server-side embedded
scripting language. Added database support, file uploads, variables,
arrays, recursive functions, conditionals, iteration, regular
expressions, etc.

PHP 3 (1998) added support for ODBC data sources, multiple
platform support, email protocols (SNMP,IMAP), and new parser
written by Zeev Suraski and Andi Gutmans .

PHP 4 (2000) became an independent component of the web server
for added efficiency. The parser was renamed the Zend Engine. Many
security features were added.

PHP 5 (2004) adds Zend Engine II with object oriented programming,
robust XML support using the libxml2 library, SOAP extension for
interoperability with Web Services, SQLite has been bundled with
PHP
PHP FeaturesPHP Features

Open source / Free software.

Cross Platform to develop, to deploy, and to use.

Power,Robust, Scalable.

Web development specific.

Can be Object Oriented.

It is faster to code and faster to execute.

Large, active developer community.

20 million websites

Support for PHP is free.

Great documentation in many language www.php.net/docs.php
Why use PHP ?Why use PHP ?
1. Easy to use
Code is embedded into HTML. The PHP code is enclosed in special
start and end tags that allow you to jump into and out.
<html>
<head>
<title>Example</title>
</head>
<body>
<?php
echo “Hi , I’m a PHP script! ”;
?>
</body>
</html>
2.Cross Platform
Run on almost any web server on several Operating Systems.
One of the strongest features is the wide range of supported databases.
• Web Server : Apache, Microsoft IIS , Netscape Enterprise Server.
• Operating Systems : Unix (Solaris,Linux),Mac OS, Window
NT/98/2000/XP/2003.
• Supported Databases : dBase,Empress,FilePro (read only),
Hyperware, IBM DB2,InformixIngress,Frontbase,MySql,ODBC,Oracle
etc.
3. Cost Benefits
PHP is free. Open Source code means that the entire PHP community
will contribute towards bug fixes. There are several add-on technologies
(libraries) for PHP that are also free.
DatatypesDatatypes

PHP stores whole numbers in a platform-dependent range.

This range is typically that of 32-bit signed integers. Unsigned
integers are converted to signed values in certain situations.

Arrays can contain elements of any type that handle in PHP .

Including resources, objects, and even other arrays.

PHP also supports strings, which can be used with single quotes,
double quotes, or heredoc syntax.
What does PHP code look like?What does PHP code look like?

Structurally similar to C/C++

Supports procedural and object-oriented paradigm (to some degree)

All PHP statements end with a semi-colon

Each PHP script must be enclosed in the reserved PHP tag
<?php
…
?>
Comments in PHPComments in PHP

Standard C, C++, and shell comment symbols
// C++ and Java-style comment
# Shell-style comments
/* C-style comments
These can span multiple lines
*/
Variables in PHPVariables in PHP

PHP variables must begin with a “$” sign

Case-sensitive ($Foo != $foo != $fOo)

Global and locally-scoped variables
-- Global variables can be used anywhere
-- Local variables restricted to a function or class

Certain variable names reserved by PHP
-- Form variables ($_POST, $_GET)
-- Server variables ($_SERVER)
-- Etc.
Variable usageVariable usage
<?php
$foo = 25; // Numerical variable
$bar = “Hello”; // String variable
$foo = ($foo * 7); // Multiplies foo by
7
$bar = ($bar * 7); // Invalid
expression
?>
EchoEcho

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 exampleEcho example

PHP scripts are stored as human-readable source code and are compiled
on-the-fly to an internal format that can be executed by the PHP engine.

Code optimizers aim to reduce the runtime of the compiled code by reducing
its size and making other changes that can reduce the execution time with the
goal of improving performance.
<?php
$foo = 25; // Numerical
variable
$bar = “Hello”; // String variable
echo $bar; // Outputs Hello
echo $foo,$bar; // Outputs 25Hello
echo “5x5=”,$foo; // Outputs
5x5=25
echo “5x5=$foo”; // Outputs 5x5=25
echo ‘5x5=$foo’; // Outputs 5x5=$foo
?>
Arithmetic OperationsArithmetic Operations

$a - $b // subtraction

$a * $b // multiplication

$a / $b // division

$a += 5 // $a = $a+5 Also works for *= and /=
<?php
$a=15;
$b=30;
$total=$a+$b;
Print $total;
Print “<p><h1>$total</h1>”;
// total is 45
?>
ConcatenationConcatenation
<?php
$string1=“Hello”;
$string2=“PHP”;
$string3=$string1 . “ ” . $string2;
Print $string3;
?>
Hello PHP
Escaping the CharacterEscaping the Character

If the string has a set of double quotation marks that must remain
visible, use the  [backslash] before the quotation marks to ignore and
display them.
<?php
$heading=“”Computer Science””;
Print $heading;
?>
“Computer Science”
PHP Control StructuresPHP Control Structures

Control Structures: Are the structures within a language that allow us
to control the flow of execution through a program or script.

Grouped into conditional (branching) structures (e.g. if/else) and
repetition structures (e.g. while loops).

Example if/else if/else statement:
if ($foo == 0) {
echo ‘The variable foo is equal to 0’;
}
else if (($foo > 0) && ($foo <= 5)) {
echo ‘The variable foo is between 1 and 5’;
}
else {
echo ‘The variable foo is equal to ‘.$foo;
}
If ... Else...If ... Else...
If (condition)
{
Statements;
}
Else
{
Statement;
}
<?php
If($user==“John”)
{
Print “Hello John.”;
}
Else
{
Print “You are not John.”;
}
?>
No THEN in PHP
While LoopsWhile Loops
While (condition)
{
Statements;
}
<?php
$count=0;
While($count<3)
{
Print “hello PHP. ”;
$count += 1;
// $count = $count + 1;
// or
// $count++;
?>
hello PHP. hello PHP. hello PHP.
Date DisplayDate Display
$datedisplay=date(“yyyy/m/d”);
Print $datedisplay;
# If the date is April 1st
, 2009
# It would display as 2009/4/1
$datedisplay=date(“l, F m, Y”);
Print $datedisplay;
# If the date is April 1st
, 2009
# Wednesday, April 1, 2009
2009/4/1
Wednesday, April 1, 2009
Month, Day & Date Format SymbolsMonth, Day & Date Format Symbols
M Jan
F January
m 01
n 1
Day of Month d 01
Day of Month J 1
Day of Week l Monday
Day of Week D Mon
FunctionsFunctions

Functions MUST be defined before then can be called

Function headers are of the format
-- Note that no return type is specified

Unlike variables, function names are not case sensitive (foo(…) ==
Foo(…) == FoO(…))
function functionName($arg_1, $arg_2, …, $arg_n)
Functions exampleFunctions example
<?php
// This is a function
function foo($arg_1, $arg_2)
{
$arg_2 = $arg_1 * $arg_2;
return $arg_2;
}
$result_1 = foo(12, 3); //
Store the function
echo $result_1; // Outputs 36
echo foo(12, 3); // Outputs 36
?>
Include FilesInclude Files
Include “opendb.php”;
Include “closedb.php”;
This inserts files; the code in files will be inserted into current code.
Thiswill provide useful and protective means once you connect to a
database, as well as for other repeated functions.
Include (“footer.php”);
The file footer.php might look like:
<hr SIZE=11 NOSHADE WIDTH=“100%”>
<i>Copyright © 2008-2010 KSU </i></font><br>
<i>ALL RIGHTS RESERVED</i></font><br>
<i>URL: http://www.kent.edu</i></font><br>
PHP FormsPHP Forms

Access to the HTTP POST and GET data is simple in PHPAccess to the HTTP POST and GET data is simple in PHP

The global variables $_POST[] and $_GET[] contain the request dataThe global variables $_POST[] and $_GET[] contain the request data
<?php
if ($_POST["submit"])
echo "<h2>You clicked Submit!</h2>";
else if ($_POST["cancel"])
echo "<h2>You clicked Cancel!</h2>";
?>
<form action="form.php" method="post">
<input type="submit" name="submit" value="Submit">
<input type="submit" name="cancel" value="Cancel">
</form>
What is a cookie ?What is a cookie ?
A cookie is a small file that the server embeds on the user's
computer. Each time the same computer requests for a page
with a browser, it will send the cookie too. With PHP, you can
both create and retrieve cookie values.
How To Create a Cookie?How To Create a Cookie?

The setcookie() function is used to create cookies.
Note: The setcookie() function must appear BEFORE the
<html> tag.
setcookie(name, [value], [expire], [path], [domain], [secure]);
This sets a cookie named "uname" - that expires after ten hours.
<?php setcookie("uname", $name, time()+36000); ?>
<html> <body> …
How To Retrieve a Cookie Value?How To Retrieve a Cookie Value?

To access a cookie you just refer to the cookie name as a
variable or use $_COOKIE array

Tip: Use the isset() function to find out if a cookie has been
set.
<html> <body>
<?php
if (isset($uname))
echo "Welcome " . $uname . "!<br />";
else
echo "You are not logged in!<br />"; ?>
</body> </html>
How To Delete a Cookie ?How To Delete a Cookie ?

Cookies must be deleted with the same parameters as they
were set with. If the value argument is an empty string (""),
and all other arguments match a previous call to setcookie,
then the cookie with the specified name will be deleted from
the remote client.
What is a Session?

The session support allows you to register arbitrary numbers
of variables to be preserved across requests.

A visitor accessing your web site is assigned an unique id,
the so-called session id. This is either stored in a cookie on
the user side or is propagated in the URL.

Tip: Use the isset() function to find out if a cookie has been
set.
How to Create a Session ?

The session_start() function is used to create cookies.
<?php
session_start();
?>
How to Retrieve a Session Value ?

Register Session variable
-- session_register('var1','var2',...); // will also create a session
-- PS:Session variable will be created on using even if you will not
register it!

Use it
<?php
session_start();
if (!isset($_SESSION['count']))
$_SESSION['count'] = 0;
else
$_SESSION['count']++;
?>
Storing Session Data

The $_SESSION superglobal array can be
used to store any session data.
e.g.
$_SESSION[‘name’] = $name;
$_SESSION[‘age’] = $age;
Reading Session Data
Data is simply read back from the $_SESSION
superglobal array.
e.g.
$_SESSION[‘name’] = $name;
$_SESSION[‘age’] = $age;
How to Delete a Session Value ?

session_unregister(´varname´);
How to destroy a session:

session_destroy()
PHP DATABASE INTERACTION IN FIVE STEPS
1) Create the Connection
2) Select the Database
3) Perform Database Query
4) Use Returned Data (if any)
5) Close Connection
1. Connect with MySQL RDBMS
mysql_connect($hostName, $userName, $password) or
die("Unable to connect to host $hostName");
2. Connect with database
mysql_select_db($dbName) or die("Unable to select
database $dbName");
3. Perform Database Query
Queries: Nearly all table interaction and management is done through
queries:
Basic information searches
$query = "SELECT FirstName, LastName, DOB, Gender FROM
Patients WHERE Gender = '$Gender‘ ORDER BY FirstName
DESC";
$Patients = mysql_query($SQL);
Editing, adding, and deleting records and tables
$query = "INSERT INTO Patients (FirstName, LastName)
VALUES('$firstName', '$lastName')";
$Patients = mysql_query($SQL);
4. Process Results (if any)
• Many functions exist to work with database results
mysql_num_rows()
– Number of rows in the result set
– Useful for iterating over result set
mysql_fetch_array()
– Returns a result row as an array
– Can be associative or numeric or both (default)
– $row = mysql_fetch_array($query);
– $row[‘column name’] :: value comes from database row with specified
column name
Process Results Loop
• Easy loop for processing results:
$result = mysql_query($query;
$num_rows = mysql_num_rows($query);
for ($i=0; $i<$num_rows; $i++) {
$row = mysql_fetch_array($result);
// take action on database results here
}
5. Closing Database Connection
• mysql_close()
– Closes database connection
– Only works for connections opened with mysql_connect()
– Connections opened with mysql_pconnect() ignore this call
– Often not necessary to call this, as connections created by
mysql_connect are closed at the end of the script anyway
THAN ”Q”

Mais conteúdo relacionado

Mais procurados (20)

PHP
PHPPHP
PHP
 
Php introduction
Php introductionPhp introduction
Php introduction
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
 
Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
 
PHP
PHPPHP
PHP
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Unit 1 php_basics
Unit 1 php_basicsUnit 1 php_basics
Unit 1 php_basics
 
Php Ppt
Php PptPhp Ppt
Php Ppt
 
Php notes
Php notesPhp notes
Php notes
 
Php intro
Php introPhp intro
Php intro
 
Php
PhpPhp
Php
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 

Semelhante a Php Tutorial

Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbaiUnmesh Baile
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPwahidullah mudaser
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckrICh morrow
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessoradeel990
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)Guni Sonow
 
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...anshkhurana01
 
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)Muhamad Al Imran
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysqldurai arasan
 
Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbaivibrantuser
 

Semelhante a Php Tutorial (20)

PHP
PHPPHP
PHP
 
Prersentation
PrersentationPrersentation
Prersentation
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbai
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessor
 
Php
PhpPhp
Php
 
php basics
php basicsphp basics
php basics
 
Php
PhpPhp
Php
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
 
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
PhpPhp
Php
 
Php basics
Php basicsPhp basics
Php basics
 
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)
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
 
Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbai
 

Último

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Último (20)

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Php Tutorial

  • 1. PHP (Hypertext Preprocessor) -Gursharandeep kaur bajwa (CTIEMT) 100220314317
  • 2. IntroductionIntroduction  PHP is stands for ’Hypertext Preprocessor ’ used for making dynamic web pages and interactive web pages.  PHP is server side scripting language intented to help web developers build dynamic web pages.  PHP scripts are executed on the server.  PHP supports many databases (MySql ,Oracle,PostgreSQL,Generic ODBC etc).  PHP was created by Rasmus Lerdrof in 1995.  PHP originally stood for ”PERSONAL HOME PAGE”  PHP is an Open Source software.  PHP is free to download and use.
  • 3. PHP FilesPHP Files  PHP files can contain text, HTML Tags and scripts.  PHP files are returned to the browser as plain HTML  PHP files have a file extension of ”.php”. EXECUTION OF PHP PAGE
  • 4. “PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C,Java & Perl with a couple of unique PHP-specific features thrown in .The goal of the language is to allow web developers to write dynamically generated pages quickly. ”
  • 5. Brief History of PHPBrief History of PHP PHP (PHP: Hypertext Preprocessor) was created by Rasmus Lerdorf in 1994. It was initially developed for HTTP usage logging and server- side form generation in Unix  PHP 2 (1995) transformed the language into a Server-side embedded scripting language. Added database support, file uploads, variables, arrays, recursive functions, conditionals, iteration, regular expressions, etc.  PHP 3 (1998) added support for ODBC data sources, multiple platform support, email protocols (SNMP,IMAP), and new parser written by Zeev Suraski and Andi Gutmans .  PHP 4 (2000) became an independent component of the web server for added efficiency. The parser was renamed the Zend Engine. Many security features were added.
  • 6.  PHP 5 (2004) adds Zend Engine II with object oriented programming, robust XML support using the libxml2 library, SOAP extension for interoperability with Web Services, SQLite has been bundled with PHP
  • 7. PHP FeaturesPHP Features  Open source / Free software.  Cross Platform to develop, to deploy, and to use.  Power,Robust, Scalable.  Web development specific.  Can be Object Oriented.  It is faster to code and faster to execute.  Large, active developer community.  20 million websites  Support for PHP is free.  Great documentation in many language www.php.net/docs.php
  • 8. Why use PHP ?Why use PHP ? 1. Easy to use Code is embedded into HTML. The PHP code is enclosed in special start and end tags that allow you to jump into and out. <html> <head> <title>Example</title> </head>
  • 9. <body> <?php echo “Hi , I’m a PHP script! ”; ?> </body> </html>
  • 10. 2.Cross Platform Run on almost any web server on several Operating Systems. One of the strongest features is the wide range of supported databases. • Web Server : Apache, Microsoft IIS , Netscape Enterprise Server. • Operating Systems : Unix (Solaris,Linux),Mac OS, Window NT/98/2000/XP/2003. • Supported Databases : dBase,Empress,FilePro (read only), Hyperware, IBM DB2,InformixIngress,Frontbase,MySql,ODBC,Oracle etc.
  • 11. 3. Cost Benefits PHP is free. Open Source code means that the entire PHP community will contribute towards bug fixes. There are several add-on technologies (libraries) for PHP that are also free.
  • 12. DatatypesDatatypes  PHP stores whole numbers in a platform-dependent range.  This range is typically that of 32-bit signed integers. Unsigned integers are converted to signed values in certain situations.  Arrays can contain elements of any type that handle in PHP .  Including resources, objects, and even other arrays.  PHP also supports strings, which can be used with single quotes, double quotes, or heredoc syntax.
  • 13. What does PHP code look like?What does PHP code look like?  Structurally similar to C/C++  Supports procedural and object-oriented paradigm (to some degree)  All PHP statements end with a semi-colon  Each PHP script must be enclosed in the reserved PHP tag <?php … ?>
  • 14. Comments in PHPComments in PHP  Standard C, C++, and shell comment symbols // C++ and Java-style comment # Shell-style comments /* C-style comments These can span multiple lines */
  • 15. Variables in PHPVariables in PHP  PHP variables must begin with a “$” sign  Case-sensitive ($Foo != $foo != $fOo)  Global and locally-scoped variables -- Global variables can be used anywhere -- Local variables restricted to a function or class  Certain variable names reserved by PHP -- Form variables ($_POST, $_GET) -- Server variables ($_SERVER) -- Etc.
  • 16. Variable usageVariable usage <?php $foo = 25; // Numerical variable $bar = “Hello”; // String variable $foo = ($foo * 7); // Multiplies foo by 7 $bar = ($bar * 7); // Invalid expression ?>
  • 17. EchoEcho  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
  • 18. Echo exampleEcho example  PHP scripts are stored as human-readable source code and are compiled on-the-fly to an internal format that can be executed by the PHP engine.  Code optimizers aim to reduce the runtime of the compiled code by reducing its size and making other changes that can reduce the execution time with the goal of improving performance. <?php $foo = 25; // Numerical variable $bar = “Hello”; // String variable echo $bar; // Outputs Hello echo $foo,$bar; // Outputs 25Hello echo “5x5=”,$foo; // Outputs 5x5=25 echo “5x5=$foo”; // Outputs 5x5=25 echo ‘5x5=$foo’; // Outputs 5x5=$foo ?>
  • 19. Arithmetic OperationsArithmetic Operations  $a - $b // subtraction  $a * $b // multiplication  $a / $b // division  $a += 5 // $a = $a+5 Also works for *= and /= <?php $a=15; $b=30; $total=$a+$b; Print $total; Print “<p><h1>$total</h1>”; // total is 45 ?>
  • 21. Escaping the CharacterEscaping the Character  If the string has a set of double quotation marks that must remain visible, use the [backslash] before the quotation marks to ignore and display them. <?php $heading=“”Computer Science””; Print $heading; ?> “Computer Science”
  • 22. PHP Control StructuresPHP Control Structures  Control Structures: Are the structures within a language that allow us to control the flow of execution through a program or script.  Grouped into conditional (branching) structures (e.g. if/else) and repetition structures (e.g. while loops).  Example if/else if/else statement: if ($foo == 0) { echo ‘The variable foo is equal to 0’; } else if (($foo > 0) && ($foo <= 5)) { echo ‘The variable foo is between 1 and 5’; } else { echo ‘The variable foo is equal to ‘.$foo; }
  • 23. If ... Else...If ... Else... If (condition) { Statements; } Else { Statement; } <?php If($user==“John”) { Print “Hello John.”; } Else { Print “You are not John.”; } ?> No THEN in PHP
  • 24. While LoopsWhile Loops While (condition) { Statements; } <?php $count=0; While($count<3) { Print “hello PHP. ”; $count += 1; // $count = $count + 1; // or // $count++; ?> hello PHP. hello PHP. hello PHP.
  • 25. Date DisplayDate Display $datedisplay=date(“yyyy/m/d”); Print $datedisplay; # If the date is April 1st , 2009 # It would display as 2009/4/1 $datedisplay=date(“l, F m, Y”); Print $datedisplay; # If the date is April 1st , 2009 # Wednesday, April 1, 2009 2009/4/1 Wednesday, April 1, 2009
  • 26. Month, Day & Date Format SymbolsMonth, Day & Date Format Symbols M Jan F January m 01 n 1 Day of Month d 01 Day of Month J 1 Day of Week l Monday Day of Week D Mon
  • 27. FunctionsFunctions  Functions MUST be defined before then can be called  Function headers are of the format -- Note that no return type is specified  Unlike variables, function names are not case sensitive (foo(…) == Foo(…) == FoO(…)) function functionName($arg_1, $arg_2, …, $arg_n)
  • 28. Functions exampleFunctions example <?php // This is a function function foo($arg_1, $arg_2) { $arg_2 = $arg_1 * $arg_2; return $arg_2; } $result_1 = foo(12, 3); // Store the function echo $result_1; // Outputs 36 echo foo(12, 3); // Outputs 36 ?>
  • 29. Include FilesInclude Files Include “opendb.php”; Include “closedb.php”; This inserts files; the code in files will be inserted into current code. Thiswill provide useful and protective means once you connect to a database, as well as for other repeated functions. Include (“footer.php”); The file footer.php might look like: <hr SIZE=11 NOSHADE WIDTH=“100%”> <i>Copyright © 2008-2010 KSU </i></font><br> <i>ALL RIGHTS RESERVED</i></font><br> <i>URL: http://www.kent.edu</i></font><br>
  • 30. PHP FormsPHP Forms  Access to the HTTP POST and GET data is simple in PHPAccess to the HTTP POST and GET data is simple in PHP  The global variables $_POST[] and $_GET[] contain the request dataThe global variables $_POST[] and $_GET[] contain the request data <?php if ($_POST["submit"]) echo "<h2>You clicked Submit!</h2>"; else if ($_POST["cancel"]) echo "<h2>You clicked Cancel!</h2>"; ?> <form action="form.php" method="post"> <input type="submit" name="submit" value="Submit"> <input type="submit" name="cancel" value="Cancel"> </form>
  • 31. What is a cookie ?What is a cookie ? A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests for a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.
  • 32. How To Create a Cookie?How To Create a Cookie?  The setcookie() function is used to create cookies. Note: The setcookie() function must appear BEFORE the <html> tag. setcookie(name, [value], [expire], [path], [domain], [secure]); This sets a cookie named "uname" - that expires after ten hours. <?php setcookie("uname", $name, time()+36000); ?> <html> <body> …
  • 33. How To Retrieve a Cookie Value?How To Retrieve a Cookie Value?  To access a cookie you just refer to the cookie name as a variable or use $_COOKIE array  Tip: Use the isset() function to find out if a cookie has been set. <html> <body> <?php if (isset($uname)) echo "Welcome " . $uname . "!<br />"; else echo "You are not logged in!<br />"; ?> </body> </html>
  • 34. How To Delete a Cookie ?How To Delete a Cookie ?  Cookies must be deleted with the same parameters as they were set with. If the value argument is an empty string (""), and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client.
  • 35. What is a Session?  The session support allows you to register arbitrary numbers of variables to be preserved across requests.  A visitor accessing your web site is assigned an unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.  Tip: Use the isset() function to find out if a cookie has been set.
  • 36. How to Create a Session ?  The session_start() function is used to create cookies. <?php session_start(); ?>
  • 37. How to Retrieve a Session Value ?  Register Session variable -- session_register('var1','var2',...); // will also create a session -- PS:Session variable will be created on using even if you will not register it!  Use it <?php session_start(); if (!isset($_SESSION['count'])) $_SESSION['count'] = 0; else $_SESSION['count']++; ?>
  • 38. Storing Session Data  The $_SESSION superglobal array can be used to store any session data. e.g. $_SESSION[‘name’] = $name; $_SESSION[‘age’] = $age;
  • 39. Reading Session Data Data is simply read back from the $_SESSION superglobal array. e.g. $_SESSION[‘name’] = $name; $_SESSION[‘age’] = $age;
  • 40. How to Delete a Session Value ?  session_unregister(´varname´); How to destroy a session:  session_destroy()
  • 41. PHP DATABASE INTERACTION IN FIVE STEPS 1) Create the Connection 2) Select the Database 3) Perform Database Query 4) Use Returned Data (if any) 5) Close Connection
  • 42. 1. Connect with MySQL RDBMS mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");
  • 43. 2. Connect with database mysql_select_db($dbName) or die("Unable to select database $dbName");
  • 44. 3. Perform Database Query Queries: Nearly all table interaction and management is done through queries: Basic information searches $query = "SELECT FirstName, LastName, DOB, Gender FROM Patients WHERE Gender = '$Gender‘ ORDER BY FirstName DESC"; $Patients = mysql_query($SQL); Editing, adding, and deleting records and tables $query = "INSERT INTO Patients (FirstName, LastName) VALUES('$firstName', '$lastName')"; $Patients = mysql_query($SQL);
  • 45. 4. Process Results (if any) • Many functions exist to work with database results mysql_num_rows() – Number of rows in the result set – Useful for iterating over result set mysql_fetch_array() – Returns a result row as an array – Can be associative or numeric or both (default) – $row = mysql_fetch_array($query); – $row[‘column name’] :: value comes from database row with specified column name
  • 46. Process Results Loop • Easy loop for processing results: $result = mysql_query($query; $num_rows = mysql_num_rows($query); for ($i=0; $i<$num_rows; $i++) { $row = mysql_fetch_array($result); // take action on database results here }
  • 47. 5. Closing Database Connection • mysql_close() – Closes database connection – Only works for connections opened with mysql_connect() – Connections opened with mysql_pconnect() ignore this call – Often not necessary to call this, as connections created by mysql_connect are closed at the end of the script anyway