SlideShare a Scribd company logo
PHP
Krishna priya
April 19, 2011
C-DAC, Hyderabad
What is PHP?
PHP == ‘Hypertext Preprocessor’
Open-source, server-side scripting
language
Used to generate dynamic web-pages
PHP scripts reside between reserved PHP
tags
This allows the programmer to embed PHP
scripts within HTML pages
What is PHP (cont’d)
Interpreted language, scripts are parsed at runtime rather than compiled beforehand
Executed on the server-side
Source-code not visible by client
‘View Source’ in browsers does not display the PHP code

Various built-in functions allow for fast
development
Compatible with many popular databases
including MySQL, PostgreSQL, Oracle, Sybase,
Informix, and Microsoft SQL Server.
Brief History of PHP
PHP (PHP: Hypertext Preprocessor) was created
by Rasmus Lerdorf in 1994. It was initially
developed for HTTP usage logging and serverside 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(Open
Database Connectivity) data sources, multiple
platform support, email protocols and new parser
written
Brief History of PHP (cont’d)
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,
SOAP extension for interoperability with Web
Services, SQLite(SQLite is an embedded database
library that implements a large subset of the SQL
92 standard.) has been bundled with PHP
Advantages of selecting PHP for
Web Development
1. It can be easily embedded into the HTML code.
2. There is no need to pay for using PHP to develop web applications and
websites.
3. It provides support to almost all operating systems that include Windows,
Linux, Mac, etc.
4. Implementing PHP is much easier than other programming languages like
Java, Asp.net, C++, etc.
5. PHP provides compatibility to all web browsers. Be it Internet Explorer,
Mozilla Firefox, Netscape, Google Chrome, Opera, or any other Web
browser, PHP supports all.
6. PHP is compatible with web servers like Apache, IIS, etc.
7. PHP Web development is highly reliable and secure because of the security
features that PHP offers.
8. Provides support to all database servers, such as MSSQL, Oracle, and
MySQL. Because it provides supports for almost all database servers, it is
highly used in developing dynamic web applications.
9. It is the best choice to develop small as well as large websites like
ecommerce websites, discussion forums, etc.
10. It offers flexibility, scalability, and faster speed in comparison to other
scripting languages being used to develop websites.
PHP Environment Setup
In order to develop and run PHP Web
pages three vital components need to be
installed on your computer system.
Web Server, Database , PHP Parser
Wamp Server is an open source project
http://www.wampserver.com/en/dow
nload.php
Wamp Server Version 2.0
PHP:5.2.5, Apache:2.2.6,
MYSQL:5.0.45
How PHP works
When a user navigates in his/her browser to a page that ends
with a .php extension, the request is sent to a web server, which
directs the request to the PHP interpreter.
What does PHP code look like?
Structurally similar to C/C++
Here some similarities and differences in PHP and
C:
Similarities:
Broadly speaking, PHP syntax is the same as in
C:
statements are terminated with semicolons,
function calls have the same structure
(my_function(expression1, expression2)), and curly
braces ({ and }) make statements into blocks.
PHP supports C and C++-style comments (/* */ as well
as //), and also Perl and shell-script style (#).
Similarities(cont’d)
Operators:
The assignment operators (=, +=, *=, and so on),
Boolean operators (&&, ||, !)
the comparison operators (<,>, <=, >=, ==, !=), and
the basic arithmetic operators (+, -, *, /, %) all behave
in PHP as they do in C.

Control structures:
The basic control structures (if, switch, while, for)
behave as they do in C, including supporting break and
continue.
One notable difference is that switch in PHP can accept
strings as case identifiers.
Similarities (cont’d)
Function names:
As you peruse the documentation, you all see
many function names that seem identical to C
functions.

Differences:
Dollar signs:
All variables are denoted with a leading $.
Variables do not need to be declared in
advance of assignment
Differences compare to C
Types:
PHP has only two numerical types: integer
(corresponding to a long in C) and double
(corresponding to a double in C). Strings are of arbitrary
length. There is no separate character type.

Arrays:
Arrays have a syntax superficially similar to C's array
syntax, but they are implemented completely differently.
They are actually associative arrays or hashes, and the
index can be either a number or a string. They do not
need to be declared or allocated in advance.
Differences compare to C
No structure type:
There is no struct in PHP

No pointers:
There are no pointers available in PHP.
PHP does support variable references. You can
also emulate function pointers to some extent,
in that function names can be stored in
variables and called by using the variable
rather than a literal name.
Differences compare to C
No prototypes:
Functions do not need to be declared before
their implementation is defined, as long as the
function definition can be found somewhere in
the current code file or included files.
PHP Language Basics
Structurally similar to C/C++
All PHP statements end with a semi-colon
Each PHP script must be enclosed in the reserved
PHP tag
PHP Tag Styles as follows:
<?php
…
?>

short-open tag
<?...?>

ASP-style tags
<%...%>

HTML script tags
<script language="PHP">...</script>
Comments in PHP
There are two commenting formats in
PHP:
1. Single-line comments
2. Multi-lines comments
// C++ and Java-style comment
# This is the second line of the comment
/* C-style comments
These can span multiple lines */
PHP Variables
PHP variables must begin with a “$” sign
Case-sensitive ($Foo != $foo != $fOo)
Certain variable names reserved by PHP
For Example Form variables ($_POST,
$_GET) Etc.
<?php
$foo = 25;
$bar = “Hello”;

// Numerical variable
// String variable

$foo = ($foo * 7); // Multiplies foo by 7
?>
PHP Variable Naming Conventions
There are a few rules that you need to follow when
choosing a name for your PHP variables.
PHP variables must start with a letter or underscore "_".
PHP variables may only be comprised of alpha-numeric
characters and underscores. a-z, A-Z, 0-9, or _ .
Variables with more than one word should be separated
with underscores. $my_variable
Variables with more than one word can also be
distinguished with capitalization. $myVariable
Echo
The PHP command ‘echo’ is used to output the parameters passed
to it
Strings in single quotes (‘ ’) are not interpreted or evaluated by
PHP
<?php
$foo = 25;
$bar = “Hello”;
echo
echo
echo
echo
echo
?>

// Numerical variable
// String variable

$bar;
// Outputs Hello
$foo,$bar; // Outputs 25Hello
“5x5=”,$foo;
// Outputs 5x5=25
“5x5=$foo”; // Outputs 5x5=25
‘5x5=$foo’; // Outputs 5x5=$foo

Notice how echo ‘5x5=$foo’ outputs $foo rather than replacing it with 25
Strings in single quotes (‘ ’) are not interpreted or evaluated by PHP
Concatenation
Use a period to join strings into one.
<?php
$string1=“Hello”;
$string2=“PHP”;
$string3=$string1 . “ ” . $string2;
echo $string3;
?>

Hello PHP

Escaping 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”
Operators Examples
Assume variable A holds 10 and variable B holds 20 then:
Type

Operator

Description

Example

Arithmetic

+

Adds two operands

A + B will give 30

Comparision

==

Checks if the value of two
operands are equal or not,
if yes then condition
becomes true.

(A == B) is not
true.

Logical (or Relational)
Operators

and

If both the operands are
true then then condition
becomes true.

(A and B) is true.

Assignment Operators

+=

It adds right operand to
the left operand and
assign the result to left
operand

C += A is
equivalent to C =
C+A

Conditional (or ternary)
Operators

?:

Conditional Expression

If Condition is
true ? Then value
X : Otherwise
value Y
PHP Decision Making
The if, else …elseif and switch statements
are used to take decision based on the
different condition.
<?php
$my_name = "someguy";
if ( $my_name == "someguy" )
{
echo "Your name is
someguy!<br />";
}
echo "Welcome to my
homepage!";
?>
No THEN in PHP

<?php
If($user==“John”)
{
Print “Hello John.”;
}
Else
{
Print “You are not
John.”;
}
?>
PHP Loop Types
Loops in PHP are used to execute the same block of code a
specified number of times. PHP supports following four loop
types.
While

while - loops through a block of code if and as
long as a specified condition is true.

do...while

do...while - loops through a block of code once,
and then repeats the loop as long as a special
condition is true.

for – loop

for - loops through a block of code a specified
number of times.

foreach

foreach - loops through a block of code for each
element in an array.
PHP Arrays
An array stores one or more similar type of
values in a single value.
An array is a special variable, which can store
multiple values in one single variable.
In PHP, there are three kind of arrays:
Numeric array - An array with a numeric index
Associative array - An array where each ID key is
associated with a value
Multidimensional array - An array containing one
or more arrays
Looping through Arrays
Looping through element values
Looping through keys and values

foreach ( $array as $value ) {
// Do stuff with $value
}

foreach ( $array as $key => $value ) {
// Do stuff with $key and/or $value
}

Sorting an Array in PHP
You can sort an array in PHP by using two functions:
sort(), to sort an array in ascending order
rsort(), to sort an array in the reverse order, or descending order
Date Display
$datedisplay=date(“yyyy/m/d”);
echo $datedisplay;

2011/4/19

Tuesday, April 19, 2011

Tue

$datedisplay=date(“l, F m, Y”);
echo $datedisplay;

$date display=date(“D”);
echo $d
Functions
PHP functions are similar to other programming languages. A
function is a piece of code which takes one more input in the form
of parameter and does some processing and returns a value.
There are two parts which should be clear to you:
Creating a PHP Function
Calling a PHP Function

function functionName()
{
code to be executed;
}
PHP File Inclusion
You can include the content of a PHP file into another PHP
file before the server executes it. There are two PHP
functions which can be used to included one PHP file into
another PHP file.
The include() Function
The require() Function
This is a strong point of PHP which helps in creating functions,
headers, footers, or elements that can be reused on multiple pages.
This will help developers to make it easy to change
the layout of complete website with minimal effort.
If there is any change required then instead of changing
thausand of files just change included file.

More Related Content

What's hot (20)

php
phpphp
php
ajeetjhajharia
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
Manish Bothra
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
Spy Seat
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Anjan Banda
 
Php
PhpPhp
Php
Shyam Khant
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
JIGAR MAKHIJA
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
shanmukhareddy dasi
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
Geshan Manandhar
 
Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask Presentation
Parag Mujumdar
 
Dom
DomDom
Dom
Rakshita Upadhyay
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
Jeff Fox
 
Operators php
Operators phpOperators php
Operators php
Chandni Pm
 
PHP
PHPPHP
PHP
sometech
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Kengatharaiyer Sarveswaran
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
Computer Hardware & Trouble shooting
 

Similar to Php introduction (20)

Prersentation
PrersentationPrersentation
Prersentation
Ashwin Deora
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
SHARANBAJWA
 
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP  Declaring variables, data types, array, string, operators, Expres...Unit 5-PHP  Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
Alokin Software Pvt Ltd
 
php basic notes of concept for beginners
php basic notes of concept for beginnersphp basic notes of concept for beginners
php basic notes of concept for beginners
yashpalmodi1990
 
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 mysql
Php mysqlPhp mysql
Php mysql
Ajit Yadav
 
php41.ppt
php41.pptphp41.ppt
php41.ppt
Nishant804733
 
PHP InterLevel.ppt
PHP InterLevel.pptPHP InterLevel.ppt
PHP InterLevel.ppt
NBACriteria2SICET
 
php-I-slides.ppt
php-I-slides.pptphp-I-slides.ppt
php-I-slides.ppt
SsewankamboErma
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
HambardeAtharva
 
introduction to php web programming 2024.ppt
introduction to php web programming 2024.pptintroduction to php web programming 2024.ppt
introduction to php web programming 2024.ppt
idaaryanie
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
zalatarunk
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
Abu Bakar
 
Php i-slides (2) (1)
Php i-slides (2) (1)Php i-slides (2) (1)
Php i-slides (2) (1)
ravi18011991
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
ravi18011991
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
baabtra.com - No. 1 supplier of quality freshers
 
Introduction to PHP.pptx
Introduction to PHP.pptxIntroduction to PHP.pptx
Introduction to PHP.pptx
SherinRappai
 
Lecture14-Introduction to PHP-coding.pdf
Lecture14-Introduction to PHP-coding.pdfLecture14-Introduction to PHP-coding.pdf
Lecture14-Introduction to PHP-coding.pdf
IotenergyWater
 
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP  Declaring variables, data types, array, string, operators, Expres...Unit 5-PHP  Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
php basic notes of concept for beginners
php basic notes of concept for beginnersphp basic notes of concept for beginners
php basic notes of concept for beginners
yashpalmodi1990
 
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 - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
introduction to php web programming 2024.ppt
introduction to php web programming 2024.pptintroduction to php web programming 2024.ppt
introduction to php web programming 2024.ppt
idaaryanie
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
Abu Bakar
 
Php i-slides (2) (1)
Php i-slides (2) (1)Php i-slides (2) (1)
Php i-slides (2) (1)
ravi18011991
 
Introduction to PHP.pptx
Introduction to PHP.pptxIntroduction to PHP.pptx
Introduction to PHP.pptx
SherinRappai
 
Lecture14-Introduction to PHP-coding.pdf
Lecture14-Introduction to PHP-coding.pdfLecture14-Introduction to PHP-coding.pdf
Lecture14-Introduction to PHP-coding.pdf
IotenergyWater
 
Ad

More from krishnapriya Tadepalli (14)

Web content accessibility
Web content accessibilityWeb content accessibility
Web content accessibility
krishnapriya Tadepalli
 
Data visualization tools
Data visualization toolsData visualization tools
Data visualization tools
krishnapriya Tadepalli
 
Drupal vs sitecore comparisons
Drupal vs sitecore comparisonsDrupal vs sitecore comparisons
Drupal vs sitecore comparisons
krishnapriya Tadepalli
 
Open Source Content Management Systems
Open Source Content Management SystemsOpen Source Content Management Systems
Open Source Content Management Systems
krishnapriya Tadepalli
 
My sql vs mongo
My sql vs mongoMy sql vs mongo
My sql vs mongo
krishnapriya Tadepalli
 
Node.js
Node.jsNode.js
Node.js
krishnapriya Tadepalli
 
Json
JsonJson
Json
krishnapriya Tadepalli
 
Comparisons Wiki vs CMS
Comparisons Wiki vs CMSComparisons Wiki vs CMS
Comparisons Wiki vs CMS
krishnapriya Tadepalli
 
Sending emails through PHP
Sending emails through PHPSending emails through PHP
Sending emails through PHP
krishnapriya Tadepalli
 
PHP Making Web Forms
PHP Making Web FormsPHP Making Web Forms
PHP Making Web Forms
krishnapriya Tadepalli
 
Using advanced features in joomla
Using advanced features in joomlaUsing advanced features in joomla
Using advanced features in joomla
krishnapriya Tadepalli
 
Presentation joomla-introduction
Presentation joomla-introductionPresentation joomla-introduction
Presentation joomla-introduction
krishnapriya Tadepalli
 
Making web forms using php
Making web forms using phpMaking web forms using php
Making web forms using php
krishnapriya Tadepalli
 
Language enabling
Language enablingLanguage enabling
Language enabling
krishnapriya Tadepalli
 
Ad

Recently uploaded (20)

Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
Fortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in CybersecurityFortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in Cybersecurity
VICTOR MAESTRE RAMIREZ
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath InsightsUiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPathCommunity
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
6th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 20256th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 2025
DanBrown980551
 
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AI Emotional Actors:  “When Machines Learn to Feel and Perform"AI Emotional Actors:  “When Machines Learn to Feel and Perform"
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AkashKumar809858
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
Dev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API WorkflowsDev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API Workflows
UiPathCommunity
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
Fortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in CybersecurityFortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in Cybersecurity
VICTOR MAESTRE RAMIREZ
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath InsightsUiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPathCommunity
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
6th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 20256th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 2025
DanBrown980551
 
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AI Emotional Actors:  “When Machines Learn to Feel and Perform"AI Emotional Actors:  “When Machines Learn to Feel and Perform"
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AkashKumar809858
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
Dev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API WorkflowsDev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API Workflows
UiPathCommunity
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 

Php introduction

  • 1. PHP Krishna priya April 19, 2011 C-DAC, Hyderabad
  • 2. What is PHP? PHP == ‘Hypertext Preprocessor’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP tags This allows the programmer to embed PHP scripts within HTML pages
  • 3. What is PHP (cont’d) Interpreted language, scripts are parsed at runtime rather than compiled beforehand Executed on the server-side Source-code not visible by client ‘View Source’ in browsers does not display the PHP code Various built-in functions allow for fast development Compatible with many popular databases including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.
  • 4. Brief History of PHP PHP (PHP: Hypertext Preprocessor) was created by Rasmus Lerdorf in 1994. It was initially developed for HTTP usage logging and serverside 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(Open Database Connectivity) data sources, multiple platform support, email protocols and new parser written
  • 5. Brief History of PHP (cont’d) 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, SOAP extension for interoperability with Web Services, SQLite(SQLite is an embedded database library that implements a large subset of the SQL 92 standard.) has been bundled with PHP
  • 6. Advantages of selecting PHP for Web Development 1. It can be easily embedded into the HTML code. 2. There is no need to pay for using PHP to develop web applications and websites. 3. It provides support to almost all operating systems that include Windows, Linux, Mac, etc. 4. Implementing PHP is much easier than other programming languages like Java, Asp.net, C++, etc. 5. PHP provides compatibility to all web browsers. Be it Internet Explorer, Mozilla Firefox, Netscape, Google Chrome, Opera, or any other Web browser, PHP supports all. 6. PHP is compatible with web servers like Apache, IIS, etc. 7. PHP Web development is highly reliable and secure because of the security features that PHP offers. 8. Provides support to all database servers, such as MSSQL, Oracle, and MySQL. Because it provides supports for almost all database servers, it is highly used in developing dynamic web applications. 9. It is the best choice to develop small as well as large websites like ecommerce websites, discussion forums, etc. 10. It offers flexibility, scalability, and faster speed in comparison to other scripting languages being used to develop websites.
  • 7. PHP Environment Setup In order to develop and run PHP Web pages three vital components need to be installed on your computer system. Web Server, Database , PHP Parser Wamp Server is an open source project http://www.wampserver.com/en/dow nload.php Wamp Server Version 2.0 PHP:5.2.5, Apache:2.2.6, MYSQL:5.0.45
  • 8. How PHP works When a user navigates in his/her browser to a page that ends with a .php extension, the request is sent to a web server, which directs the request to the PHP interpreter.
  • 9. What does PHP code look like? Structurally similar to C/C++ Here some similarities and differences in PHP and C: Similarities: Broadly speaking, PHP syntax is the same as in C: statements are terminated with semicolons, function calls have the same structure (my_function(expression1, expression2)), and curly braces ({ and }) make statements into blocks. PHP supports C and C++-style comments (/* */ as well as //), and also Perl and shell-script style (#).
  • 10. Similarities(cont’d) Operators: The assignment operators (=, +=, *=, and so on), Boolean operators (&&, ||, !) the comparison operators (<,>, <=, >=, ==, !=), and the basic arithmetic operators (+, -, *, /, %) all behave in PHP as they do in C. Control structures: The basic control structures (if, switch, while, for) behave as they do in C, including supporting break and continue. One notable difference is that switch in PHP can accept strings as case identifiers.
  • 11. Similarities (cont’d) Function names: As you peruse the documentation, you all see many function names that seem identical to C functions. Differences: Dollar signs: All variables are denoted with a leading $. Variables do not need to be declared in advance of assignment
  • 12. Differences compare to C Types: PHP has only two numerical types: integer (corresponding to a long in C) and double (corresponding to a double in C). Strings are of arbitrary length. There is no separate character type. Arrays: Arrays have a syntax superficially similar to C's array syntax, but they are implemented completely differently. They are actually associative arrays or hashes, and the index can be either a number or a string. They do not need to be declared or allocated in advance.
  • 13. Differences compare to C No structure type: There is no struct in PHP No pointers: There are no pointers available in PHP. PHP does support variable references. You can also emulate function pointers to some extent, in that function names can be stored in variables and called by using the variable rather than a literal name.
  • 14. Differences compare to C No prototypes: Functions do not need to be declared before their implementation is defined, as long as the function definition can be found somewhere in the current code file or included files.
  • 15. PHP Language Basics Structurally similar to C/C++ All PHP statements end with a semi-colon Each PHP script must be enclosed in the reserved PHP tag PHP Tag Styles as follows: <?php … ?> short-open tag <?...?> ASP-style tags <%...%> HTML script tags <script language="PHP">...</script>
  • 16. Comments in PHP There are two commenting formats in PHP: 1. Single-line comments 2. Multi-lines comments // C++ and Java-style comment # This is the second line of the comment /* C-style comments These can span multiple lines */
  • 17. PHP Variables PHP variables must begin with a “$” sign Case-sensitive ($Foo != $foo != $fOo) Certain variable names reserved by PHP For Example Form variables ($_POST, $_GET) Etc. <?php $foo = 25; $bar = “Hello”; // Numerical variable // String variable $foo = ($foo * 7); // Multiplies foo by 7 ?>
  • 18. PHP Variable Naming Conventions There are a few rules that you need to follow when choosing a name for your PHP variables. PHP variables must start with a letter or underscore "_". PHP variables may only be comprised of alpha-numeric characters and underscores. a-z, A-Z, 0-9, or _ . Variables with more than one word should be separated with underscores. $my_variable Variables with more than one word can also be distinguished with capitalization. $myVariable
  • 19. Echo The PHP command ‘echo’ is used to output the parameters passed to it Strings in single quotes (‘ ’) are not interpreted or evaluated by PHP <?php $foo = 25; $bar = “Hello”; echo echo echo echo echo ?> // Numerical variable // String variable $bar; // Outputs Hello $foo,$bar; // Outputs 25Hello “5x5=”,$foo; // Outputs 5x5=25 “5x5=$foo”; // Outputs 5x5=25 ‘5x5=$foo’; // Outputs 5x5=$foo Notice how echo ‘5x5=$foo’ outputs $foo rather than replacing it with 25 Strings in single quotes (‘ ’) are not interpreted or evaluated by PHP
  • 20. Concatenation Use a period to join strings into one. <?php $string1=“Hello”; $string2=“PHP”; $string3=$string1 . “ ” . $string2; echo $string3; ?> Hello PHP Escaping 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”
  • 21. Operators Examples Assume variable A holds 10 and variable B holds 20 then: Type Operator Description Example Arithmetic + Adds two operands A + B will give 30 Comparision == Checks if the value of two operands are equal or not, if yes then condition becomes true. (A == B) is not true. Logical (or Relational) Operators and If both the operands are true then then condition becomes true. (A and B) is true. Assignment Operators += It adds right operand to the left operand and assign the result to left operand C += A is equivalent to C = C+A Conditional (or ternary) Operators ?: Conditional Expression If Condition is true ? Then value X : Otherwise value Y
  • 22. PHP Decision Making The if, else …elseif and switch statements are used to take decision based on the different condition. <?php $my_name = "someguy"; if ( $my_name == "someguy" ) { echo "Your name is someguy!<br />"; } echo "Welcome to my homepage!"; ?> No THEN in PHP <?php If($user==“John”) { Print “Hello John.”; } Else { Print “You are not John.”; } ?>
  • 23. PHP Loop Types Loops in PHP are used to execute the same block of code a specified number of times. PHP supports following four loop types. While while - loops through a block of code if and as long as a specified condition is true. do...while do...while - loops through a block of code once, and then repeats the loop as long as a special condition is true. for – loop for - loops through a block of code a specified number of times. foreach foreach - loops through a block of code for each element in an array.
  • 24. PHP Arrays An array stores one or more similar type of values in a single value. An array is a special variable, which can store multiple values in one single variable. In PHP, there are three kind of arrays: Numeric array - An array with a numeric index Associative array - An array where each ID key is associated with a value Multidimensional array - An array containing one or more arrays
  • 25. Looping through Arrays Looping through element values Looping through keys and values foreach ( $array as $value ) { // Do stuff with $value } foreach ( $array as $key => $value ) { // Do stuff with $key and/or $value } Sorting an Array in PHP You can sort an array in PHP by using two functions: sort(), to sort an array in ascending order rsort(), to sort an array in the reverse order, or descending order
  • 26. Date Display $datedisplay=date(“yyyy/m/d”); echo $datedisplay; 2011/4/19 Tuesday, April 19, 2011 Tue $datedisplay=date(“l, F m, Y”); echo $datedisplay; $date display=date(“D”); echo $d
  • 27. Functions PHP functions are similar to other programming languages. A function is a piece of code which takes one more input in the form of parameter and does some processing and returns a value. There are two parts which should be clear to you: Creating a PHP Function Calling a PHP Function function functionName() { code to be executed; }
  • 28. PHP File Inclusion You can include the content of a PHP file into another PHP file before the server executes it. There are two PHP functions which can be used to included one PHP file into another PHP file. The include() Function The require() Function This is a strong point of PHP which helps in creating functions, headers, footers, or elements that can be reused on multiple pages. This will help developers to make it easy to change the layout of complete website with minimal effort. If there is any change required then instead of changing thausand of files just change included file.