SlideShare a Scribd company logo
PHP
BASICS
Self learning by
V.S.Hewitt
Introduction
• Can be embedded into webpages and has the syntax similar to C, C++.
Embedding PHP codes in web pages:
It is possible to insert PHP codes directly into Html
pages.
Default Syntax
The default delimiter syntax opens with <?php and
concludes with ?>
Short-Tags:
<?
print "This is another PHP example.";
?>
Short-circuit syntax:
<?="This is another PHP example.";?>
Script:
<script language="php">
print "This is another PHP example.";
</script>
Commenting Your Code
Single-Line C++ Syntax:
// Title: My first PHP script
Shell Syntax:
# Title: My PHP program
Multiple-Line C Syntax: /*………….*/
Outputting Data to the Browser:
A prototype is simply the function’s definition,
formalizing its name, input parameters,and the type of
value it returns, defined by a datatype.
The print() Statement: int print(argument)
<?php
print("<p>I love the summertime.</p>");
?>
<?php
$season = "summertime";
print "<p>I love the $season.</p>";
?>
echo $heavyweight, " and ", $lightweight, " are great fighters.";
Echo can be used to print out multiple arguments.
The printf() Statement:
boolean printf(string format [, mixed args])
It separates the static and dynamic data into two
distinct sections,
printf("Bar inventory: %d bottles of tonic water.", 100);
Type specifiers: %b,%c,%d,%f,%o,%s,%u,%x,%X
The sprintf() Statement:
Similar to printf(), output is assigned to a string.
string sprintf(string format [, mixed arguments])
PHP’s Supported Datatypes:
Boolean, integer(8,10,16), float, string, and array
Object:
class Appliance {
private $_power;
function setPower($status) {
$this->_power = $status;
}}
$blender = new Appliance;
Class definition and object declaration is needed.
Converting Between Datatypes Using Type Casting:
(datatype)variable- convert variable to ‘datatype’
$score = (int) 14.8; // $score = 14
*any datatype can be cast as an object.
print $ obj->scalar; // returns "Toyota"
Adapting Datatypes with Type Juggling:
Variables are sometimes automatically
Cast to best fit the circumstances.
<?php
$total = 5; // an integer
$count = "15"; // a string
$total += $count; // $total = 20 (an integer)
?>
<?php
$total = "45 fire engines";
$incoming = 10;
$total = $incoming + $total; // $total = 55
?>
Type-Related Functions:
string gettype (mixed var)-gives variable type.
boolean settype(mixed var, string type)-converts the variable
to the specified type.
Type Identifier Functions:
is_array(), is_bool(),is_float(), is_integer(), is_null(),
is_numeric(), is_object(), is_resource(), is_scalar(), and
is_string().
Identifiers(case sensitive): (not a keyword)
variables, functions, and various other userdefined
objects.(must begin with a letter or an underscore.)
Variables: can store different values at different times.
Variable Declaration: always begins with a dollar sign $
variables do not have to be explicitly declared in PHP .
Value Assignment:
By value: By reference:
$color = "red"; <?php
$number = 12; $value1 = "Hello";
$age = 12; $value2 =& $value1;//Both “Goodbye”
$sum = 12 + "15"; // $sum = 27 $value2 = "Goodbye"; ?>
Variable Scope:Local variables(declared in a function),
Function parameters(only pass by value), Global
variables(eg. GLOBAL $somevar;), Static variables(STATIC
$somevar;)
Superglobal :$_SERVER,$_GET,$_POST,$_COOKIE,$_FILES,$_ENV
Variable Variables:
$recipe = "spaghetti"; $$recipe = "& meatballs";(value used as variable)
echo $recipe $spaghetti;//spaghetti meatballs
echo $recipe ${$recipe};
Constants:
Cannot be modified, defined by define().
boolean define(string name, mixed value [, bool case_insensitive])
Constants are global.
Expressions: particular action in program contains
atleast one or more operands.
Operands: inputs of an expression.
Operators: symbol specifying an action.
Operator Precedence: the order in which an expression
is evaluated same as elementary maths.
Operator Associativity: how operations of same
precedence are evaluated.
Arithmetic Operators: +,-,*,/,%
Assignment Operators: =,+=,-=,*=,/=,.=(concat. Assign)
Increment and Decrement Operators: ++,--
Logical Operators: &&-AND,||-OR,!-NOT,XOR.
Equality Operators: ==,!=, === (same type)
Comparison Operators: <,>,<=,>=, ?:
Bitwise Operators: &,|,^,~,>>,<<
String Interpolation: double quotes are commonly
used and escape sequence can also be parsed. Single
quotes is used to display the content without any
interpretation of variable and escape sequences.
Escape sequences: n,r,t,,$,”
Heredoc syntax : identical identifiers, start with <<< ,
double quotes need not be escaped. Variables and
escape sequences are parsed. Identifier should be dealt
with space problems.
Control Structures:
Conditional Statements:
The if Statement: checks the given condition.
if ($_POST['guess'] == $secretNumber) echo "<p>Congratulations!</p>";
Single statement of if statement.
The else Statement: when if condition is false
The elseif Statement: either-or situation
The switch Statement: its similar to elseif has an action
for each possible value.
Looping Statements:
The while Statement, The do...while Statement, The for
Statement, The foreach Statement,The break and goto
Statements
File-Inclusion Statements:
The include() Statement: include(/path/to/filename)
for conditional inclusion parenthesis is important.
The include_once() :includes the file if not present otherwise
wont be executed.
The require() and require_once() statements are different to
the include statement to certain extend.

More Related Content

PPTX
PHP Basics
Muthuganesh S
 
PPT
P H P Part I, By Kian
phelios
 
PPT
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
PDF
Drupaljam xl 2019 presentation multilingualism makes better programmers
Alexander Varwijk
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PDF
Learn Java Part 2
Gurpreet singh
 
PPTX
An Introduction to Functional Programming with Javascript
Doug Sparling
 
PPTX
PHP Basics
Bhaktaraz Bhatta
 
PHP Basics
Muthuganesh S
 
P H P Part I, By Kian
phelios
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Alexander Varwijk
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
Learn Java Part 2
Gurpreet singh
 
An Introduction to Functional Programming with Javascript
Doug Sparling
 
PHP Basics
Bhaktaraz Bhatta
 

What's hot (20)

PPTX
php basics
Anmol Paul
 
PPTX
Data types in php
ilakkiya
 
PPTX
C programming(part 3)
Dr. SURBHI SAROHA
 
PPTX
Programming in C (part 2)
Dr. SURBHI SAROHA
 
PPTX
C language
TaranjeetKaur72
 
PPTX
Learn PHP Basics
McSoftsis
 
PPTX
Introduction to PHP Lecture 1
Ajay Khatri
 
PPTX
Operators in Java
Rhythm Suiwal
 
PDF
03phpbldgblock
IIUM
 
PPTX
Basics of Java Script (JS)
Ajay Khatri
 
PPTX
CSharp Language Overview Part 1
Hossein Zahed
 
PDF
Too busy sharpening the saw
anoras
 
PPTX
C Token’s
Tarun Sharma
 
PPT
Pointer in C
Sonya Akter Rupa
 
PDF
Functions in C++
Pranali Chaudhari
 
PDF
Effective PHP. Part 3
Vasily Kartashov
 
PPT
PHP - Introduction to PHP
Vibrant Technologies & Computers
 
PDF
C operators
ArghodeepPaul
 
PPTX
Fundamentals of c programming
Chitrank Dixit
 
php basics
Anmol Paul
 
Data types in php
ilakkiya
 
C programming(part 3)
Dr. SURBHI SAROHA
 
Programming in C (part 2)
Dr. SURBHI SAROHA
 
C language
TaranjeetKaur72
 
Learn PHP Basics
McSoftsis
 
Introduction to PHP Lecture 1
Ajay Khatri
 
Operators in Java
Rhythm Suiwal
 
03phpbldgblock
IIUM
 
Basics of Java Script (JS)
Ajay Khatri
 
CSharp Language Overview Part 1
Hossein Zahed
 
Too busy sharpening the saw
anoras
 
C Token’s
Tarun Sharma
 
Pointer in C
Sonya Akter Rupa
 
Functions in C++
Pranali Chaudhari
 
Effective PHP. Part 3
Vasily Kartashov
 
PHP - Introduction to PHP
Vibrant Technologies & Computers
 
C operators
ArghodeepPaul
 
Fundamentals of c programming
Chitrank Dixit
 
Ad

Similar to Php basics (20)

PPTX
Introduction to Client-Side Javascript
Julie Iskander
 
PPT
Computation Chapter 4
Inocentshuja Ahmad
 
PPT
02basics
Waheed Warraich
 
PDF
Introduction to programming c and data-structures
Pradipta Mishra
 
PPTX
Functions in C.pptx
KarthikSivagnanam2
 
PPT
An Overview Of Python With Functional Programming
Adam Getchell
 
PDF
Chapter 01 Introduction to Java by Tushar B Kute
Tushar B Kute
 
PDF
Introduction to programming c and data structures
Pradipta Mishra
 
PDF
Client sidescripting javascript
Selvin Josy Bai Somu
 
PPT
Internet Technology and its Applications
amichoksi
 
PPSX
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
PPT
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 
PPT
Php i basic chapter 3
Muhamad Al Imran
 
PPT
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
DOC
Assignment c programming
Icaii Infotech
 
PDF
Functions
SANTOSH RATH
 
PDF
C intro
SHIKHA GAUTAM
 
PDF
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Chris Adamson
 
Introduction to Client-Side Javascript
Julie Iskander
 
Computation Chapter 4
Inocentshuja Ahmad
 
02basics
Waheed Warraich
 
Introduction to programming c and data-structures
Pradipta Mishra
 
Functions in C.pptx
KarthikSivagnanam2
 
An Overview Of Python With Functional Programming
Adam Getchell
 
Chapter 01 Introduction to Java by Tushar B Kute
Tushar B Kute
 
Introduction to programming c and data structures
Pradipta Mishra
 
Client sidescripting javascript
Selvin Josy Bai Somu
 
Internet Technology and its Applications
amichoksi
 
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 
Php i basic chapter 3
Muhamad Al Imran
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
Assignment c programming
Icaii Infotech
 
Functions
SANTOSH RATH
 
C intro
SHIKHA GAUTAM
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Chris Adamson
 
Ad

Recently uploaded (20)

PPT
Overview of Oracle Receivables Process.ppt
nbvreddy229
 
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
PDF
Rise With SAP partner in Mumbai.........
pts464036
 
PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Tier1 app
 
PPTX
introduction to dart --- Section one .pptx
marknaiem92
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PPTX
Hire Expert Blazor Developers | Scalable Solutions by OnestopDA
OnestopDA
 
PPTX
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
RanuFajar1
 
PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
PDF
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
PPTX
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PPTX
Audio Editing and it's techniques in computer graphics.pptx
fosterbayirinia3
 
PDF
Why Should Businesses Extract Cuisine Types Data from Multiple U.S. Food Apps...
devilbrown689
 
PDF
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
PDF
The Role of Automation and AI in EHS Management for Data Centers.pdf
TECH EHS Solution
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
Overview of Oracle Receivables Process.ppt
nbvreddy229
 
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
Rise With SAP partner in Mumbai.........
pts464036
 
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Tier1 app
 
introduction to dart --- Section one .pptx
marknaiem92
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
Hire Expert Blazor Developers | Scalable Solutions by OnestopDA
OnestopDA
 
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
Materi-Enum-and-Record-Data-Type (1).pptx
RanuFajar1
 
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
Audio Editing and it's techniques in computer graphics.pptx
fosterbayirinia3
 
Why Should Businesses Extract Cuisine Types Data from Multiple U.S. Food Apps...
devilbrown689
 
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
The Role of Automation and AI in EHS Management for Data Centers.pdf
TECH EHS Solution
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 

Php basics

  • 2. Introduction • Can be embedded into webpages and has the syntax similar to C, C++. Embedding PHP codes in web pages: It is possible to insert PHP codes directly into Html pages. Default Syntax The default delimiter syntax opens with <?php and concludes with ?> Short-Tags: <? print "This is another PHP example."; ?> Short-circuit syntax: <?="This is another PHP example.";?> Script: <script language="php"> print "This is another PHP example."; </script> Commenting Your Code Single-Line C++ Syntax: // Title: My first PHP script Shell Syntax: # Title: My PHP program Multiple-Line C Syntax: /*………….*/
  • 3. Outputting Data to the Browser: A prototype is simply the function’s definition, formalizing its name, input parameters,and the type of value it returns, defined by a datatype. The print() Statement: int print(argument) <?php print("<p>I love the summertime.</p>"); ?> <?php $season = "summertime"; print "<p>I love the $season.</p>"; ?> echo $heavyweight, " and ", $lightweight, " are great fighters."; Echo can be used to print out multiple arguments. The printf() Statement: boolean printf(string format [, mixed args]) It separates the static and dynamic data into two distinct sections, printf("Bar inventory: %d bottles of tonic water.", 100); Type specifiers: %b,%c,%d,%f,%o,%s,%u,%x,%X The sprintf() Statement: Similar to printf(), output is assigned to a string. string sprintf(string format [, mixed arguments]) PHP’s Supported Datatypes: Boolean, integer(8,10,16), float, string, and array Object: class Appliance { private $_power; function setPower($status) { $this->_power = $status; }} $blender = new Appliance; Class definition and object declaration is needed. Converting Between Datatypes Using Type Casting: (datatype)variable- convert variable to ‘datatype’ $score = (int) 14.8; // $score = 14 *any datatype can be cast as an object. print $ obj->scalar; // returns "Toyota"
  • 4. Adapting Datatypes with Type Juggling: Variables are sometimes automatically Cast to best fit the circumstances. <?php $total = 5; // an integer $count = "15"; // a string $total += $count; // $total = 20 (an integer) ?> <?php $total = "45 fire engines"; $incoming = 10; $total = $incoming + $total; // $total = 55 ?> Type-Related Functions: string gettype (mixed var)-gives variable type. boolean settype(mixed var, string type)-converts the variable to the specified type. Type Identifier Functions: is_array(), is_bool(),is_float(), is_integer(), is_null(), is_numeric(), is_object(), is_resource(), is_scalar(), and is_string(). Identifiers(case sensitive): (not a keyword) variables, functions, and various other userdefined objects.(must begin with a letter or an underscore.) Variables: can store different values at different times. Variable Declaration: always begins with a dollar sign $ variables do not have to be explicitly declared in PHP . Value Assignment: By value: By reference: $color = "red"; <?php $number = 12; $value1 = "Hello"; $age = 12; $value2 =& $value1;//Both “Goodbye” $sum = 12 + "15"; // $sum = 27 $value2 = "Goodbye"; ?> Variable Scope:Local variables(declared in a function), Function parameters(only pass by value), Global variables(eg. GLOBAL $somevar;), Static variables(STATIC $somevar;) Superglobal :$_SERVER,$_GET,$_POST,$_COOKIE,$_FILES,$_ENV
  • 5. Variable Variables: $recipe = "spaghetti"; $$recipe = "& meatballs";(value used as variable) echo $recipe $spaghetti;//spaghetti meatballs echo $recipe ${$recipe}; Constants: Cannot be modified, defined by define(). boolean define(string name, mixed value [, bool case_insensitive]) Constants are global. Expressions: particular action in program contains atleast one or more operands. Operands: inputs of an expression. Operators: symbol specifying an action. Operator Precedence: the order in which an expression is evaluated same as elementary maths. Operator Associativity: how operations of same precedence are evaluated. Arithmetic Operators: +,-,*,/,% Assignment Operators: =,+=,-=,*=,/=,.=(concat. Assign) Increment and Decrement Operators: ++,-- Logical Operators: &&-AND,||-OR,!-NOT,XOR. Equality Operators: ==,!=, === (same type) Comparison Operators: <,>,<=,>=, ?: Bitwise Operators: &,|,^,~,>>,<< String Interpolation: double quotes are commonly used and escape sequence can also be parsed. Single quotes is used to display the content without any interpretation of variable and escape sequences. Escape sequences: n,r,t,,$,” Heredoc syntax : identical identifiers, start with <<< , double quotes need not be escaped. Variables and escape sequences are parsed. Identifier should be dealt with space problems. Control Structures: Conditional Statements: The if Statement: checks the given condition. if ($_POST['guess'] == $secretNumber) echo "<p>Congratulations!</p>"; Single statement of if statement. The else Statement: when if condition is false The elseif Statement: either-or situation The switch Statement: its similar to elseif has an action for each possible value.
  • 6. Looping Statements: The while Statement, The do...while Statement, The for Statement, The foreach Statement,The break and goto Statements File-Inclusion Statements: The include() Statement: include(/path/to/filename) for conditional inclusion parenthesis is important. The include_once() :includes the file if not present otherwise wont be executed. The require() and require_once() statements are different to the include statement to certain extend.