SlideShare a Scribd company logo
UNIT- 1
BASICS OF PHP
What is PHP?
•PHP is an acronym for "PHP: Hypertext Preprocessor“.
•PHP is a widely-used, open source scripting language
•PHP scripts are executed on the server
•PHP is free to download and use.
•PHP files can contain text, HTML, CSS, JavaScript, and PHP code
•PHP code is executed on the server, and the result is returned to the browser as plain HTML.
•PHP files have extension ".php"
What Can PHP Do?
•PHP can generate dynamic page content
•PHP can create, open, read, write, delete, and close files on the server
•PHP can collect form data
•PHP can send and receive cookies
•PHP can add, delete, modify data in your database
•PHP can be used to control user-access
•PHP can encrypt data
• PHP was conceived sometime in the fall of 1994 by Rasmus
Lerdorf. Early non-released versions were used on his
home page to keep track of who was looking at his online
resume.
• The first version used by others was available sometime in
early 1995 and was known as the Personal Home Page
Tools.
HISTORY OF PHP
Set Up PHP on Your Own PC
To run PHP code, you need the following three software on your local machine:
1.Web Server (e.g., Apache)
2.PHP (Interpreter)
3.MySQL Databases (optional)
You can separately install Web Server, PHP Interpreter, and MySQL databases, but
to make work easier, developers have made all in one setup packages
called WAMP, LAMP, MAMP, and XAMPP, which will automatically install and set up
PHP environment on your Windows, Linux or MAC machines.
The official PHP website (PHP.net) has installation instructions for PHP:
http://php.net/manual/en/install.php
Basic PHP Syntax
A PHP script can be placed anywhere in the document.
A PHP script starts with <?php and ends with ?>:
The default file extension for PHP files is ".php".
A PHP file normally contains HTML tags, and some PHP scripting code.
PHP statements end with a semicolon (;).
introduction to php and its uses in daily
PHP echo and print Statements
With PHP, there are two basic ways to get output: echo and print.
PHP echo and print Statements
• echo and print are more or less the same. They are both used to output
data to the screen.
• The differences are small: echo has no return value while print has a
return value of 1 so it can be used in expressions. echo can take multiple
parameters (although such usage is rare) while print can take one
argument. echo is marginally faster than print.
The PHP echo Statement
The echo statement can be used with or without parentheses: echo or echo().
The PHP print Statement
The print statement can be used with or without parentheses: print or print().
introduction to php and its uses in daily
introduction to php and its uses in daily
PHP Variables
A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume).
Rules for PHP variables:
•A variable starts with the $ sign, followed by the name of the
variable
•A variable name must start with a letter or the underscore
character
•A variable name cannot start with a number
•A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
•Variable names are case-sensitive ($age and $AGE are two
different variables)
introduction to php and its uses in daily
Variables are "containers" for storing information.
Remember that PHP variable names are case-sensitive!
introduction to php and its uses in daily
introduction to php and its uses in daily
PHP Variables Scope
In PHP, variables can be declared anywhere in the script.
The scope of a variable is the part of the script where the
variable can be referenced/used.
PHP has three different variable scopes:
•local
•global
•static
Global and Local Scope
A variable declared outside a function has a GLOBAL SCOPE
and can only be accessed outside a function:
introduction to php and its uses in daily
introduction to php and its uses in daily
PHP Constants
introduction to php and its uses in daily
Always start with
Alphabetic
introduction to php and its uses in daily
PHP Constants
Difference between Server Side Scripting and Client Side Scripting
Client-side Scripting
•It helps work with the front end.
•It is visible to the users.
•The scripts are run on the client browser.
•It runs on the user/client’s computer.
•It depends on the browser’s version.
•It doesn’t interact with the server to process data.
•Client side scripting involves languages such as HTML, CSS, JavaScript.
•It helps reduce the load on the server.
•It is considered to be less secure in comparison to client side scripting.
Difference between Server Side Scripting and Client Side Scripting
Server-side Scripting
•It helps work with the back end.
•It doesn’t depend on the client.
•It runs on the web server.
•It helps provide a response to every request that comes in from the user/client.
•This is not visible to the client side of the application.
•It requires the interaction with the server for the data to be process.
•Server side scripting requires languages such as PHP, ASP.net, ColdFusion, Python, Ruby on
Rails.
•It is considered to be a secure way of working with applications.
•It can be used to customize web pages.
•It can also be used to provide dynamic websites.
PHP Loops
Loops are used to execute the same block of code again and again, as long as a certain
condition is true
In PHP, we have the following loop types:
•while - loops through a block of code as long as the specified
condition is true
•do...while - loops through a block of code once, and then repeats
the loop as long as the specified condition is true
•for - loops through a block of code a specified number of times
•foreach - loops through a block of code for each element in an array
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
PHP Break and Continue
PHP Break
PHP Continue
introduction to php and its uses in daily
PHP Conditional Statements
Very often when you write code, you want to perform different actions for different conditions. You
can use conditional statements in your code to do this.
In PHP we have the following conditional statements:
•if statement - executes some code if one condition is true
•if...else statement - executes some code if a condition is true and another code if that condition
is false
•if...elseif...else statement - executes different codes for more than two conditions
•switch statement - selects one of many blocks of code to be executed
introduction to php and its uses in daily
introduction to php and its uses in daily
PHP OOP - Access Modifiers
PHP OOP - Access Modifiers
PHP OOP - Access Modifiers
PHP OOP - Access Modifiers
Properties and methods can have access modifiers which control where
they can be accessed.
There are three access modifiers:
•public - the property or method can be accessed from everywhere. This is
default.
•protected - the property or method can be accessed within the class and
by classes derived from that class.
•private - the property or method can ONLY be accessed within the class
<?php
class Fruit {
public $name;
public $color;
public $weight;
function set_name($n) { // a public function
(default)
$this->name = $n;
}
protected function set_color($n) { // a protected
function
$this->color = $n;
}
private function set_weight($n) { // a private
function
$this->weight = $n;
}
}
$mango = new Fruit();
$mango->set_name('Mango'); // OK
$mango->set_color('Yellow'); // ERROR
$mango->set_weight('300'); // ERROR
?>
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
introduction to php and its uses in daily
PHP Operators
Operators are used to perform operations on variables
and values.
PHP divides the operators in the following groups:
•Arithmetic operators
•Assignment operators
•Comparison operators
•Increment/Decrement operators
•Logical operators
•String operators
•Array operators
•Conditional assignment operators
PHP Arithmetic Operators
The PHP arithmetic operators are used with numeric values to perform common
arithmetical operations, such as addition, subtraction, multiplication etc.
https://www.w3schools.com/php/php_operators.asp
https://www.w3schools.com/php/php_operators.asp
PHP Assignment Operators
The PHP assignment operators are used with numeric values to write a value to a variable.
The basic assignment operator in PHP is "=". It means that the left operand gets set to
the value of the assignment expression on the right.
PHP Comparison Operators
The PHP comparison operators are used to compare two values (number or string):
introduction to php and its uses in daily
introduction to php and its uses in daily

More Related Content

PPTX
Php unit i
PPT
Php i-slides (2) (1)
PPT
Php i-slides
PPT
Php i-slides
PPT
Php i-slides
PPT
PHP - Introduction to PHP Fundamentals
PPTX
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
PDF
PHP in Web development and Applications.pdf
Php unit i
Php i-slides (2) (1)
Php i-slides
Php i-slides
Php i-slides
PHP - Introduction to PHP Fundamentals
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
PHP in Web development and Applications.pdf

Similar to introduction to php and its uses in daily (20)

PPTX
Php Unit 1
PPT
php41.ppt
PPT
php-I-slides.ppt
PPT
PHP InterLevel.ppt
PPTX
Web Application Development using PHP Chapter 1
PDF
WT_PHP_PART1.pdf
PDF
Introduction of PHP.pdf
PPTX
PHP ITCS 323
PPT
introduction to php web programming 2024.ppt
PDF
Introduction to PHP - Basics of PHP
PPT
PHP - Introduction to PHP - Mazenet Solution
PPTX
PPTX
INTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGE
PPT
PPT
Intro to PHP for Students and professionals
PPTX
Php by shivitomer
PDF
Lecture14-Introduction to PHP-coding.pdf
Php Unit 1
php41.ppt
php-I-slides.ppt
PHP InterLevel.ppt
Web Application Development using PHP Chapter 1
WT_PHP_PART1.pdf
Introduction of PHP.pdf
PHP ITCS 323
introduction to php web programming 2024.ppt
Introduction to PHP - Basics of PHP
PHP - Introduction to PHP - Mazenet Solution
INTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGE
Intro to PHP for Students and professionals
Php by shivitomer
Lecture14-Introduction to PHP-coding.pdf
Ad

More from vishal choudhary (20)

PPTX
mobile application using automatin using node ja java on
PPTX
mobile development using node js and java
PPTX
Pixel to Percentage conversion Convert left and right padding of a div to per...
PPTX
esponsive web design means that your website (
PPTX
function in php using like three type of function
PPTX
data base connectivity in php using msql database
PPTX
software evelopment life cycle model and example of water fall model
PPTX
software Engineering lecture on development life cycle
PPTX
strings in php how to use different data types in string
PPTX
OPEN SOURCE WEB APPLICATION DEVELOPMENT question
PPTX
web performnace optimization using css minification
PPTX
web performance optimization using style
PPTX
Data types and variables in php for writing and databse
PPTX
Data types and variables in php for writing
PPTX
Data types and variables in php for writing
PPTX
sofwtare standard for test plan it execution
PPTX
Software test policy and test plan in development
PPTX
function in php like control loop and its uses
PPTX
data type in php and its introduction to use
PPTX
PHP introduction how to create and start php
mobile application using automatin using node ja java on
mobile development using node js and java
Pixel to Percentage conversion Convert left and right padding of a div to per...
esponsive web design means that your website (
function in php using like three type of function
data base connectivity in php using msql database
software evelopment life cycle model and example of water fall model
software Engineering lecture on development life cycle
strings in php how to use different data types in string
OPEN SOURCE WEB APPLICATION DEVELOPMENT question
web performnace optimization using css minification
web performance optimization using style
Data types and variables in php for writing and databse
Data types and variables in php for writing
Data types and variables in php for writing
sofwtare standard for test plan it execution
Software test policy and test plan in development
function in php like control loop and its uses
data type in php and its introduction to use
PHP introduction how to create and start php
Ad

Recently uploaded (20)

PDF
Sunset Boulevard Student Revision Booklet
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
IMMUNIZATION PROGRAMME pptx
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
PPTX
An introduction to Dialogue writing.pptx
PDF
LDMMIA Reiki Yoga S2 L3 Vod Sample Preview
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
PPTX
Congenital Hypothyroidism pptx
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PDF
What Is Coercive Control? Understanding and Recognizing Hidden Abuse
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PDF
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
PPTX
ACUTE NASOPHARYNGITIS. pptx
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Sunset Boulevard Student Revision Booklet
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
IMMUNIZATION PROGRAMME pptx
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
vedic maths in python:unleasing ancient wisdom with modern code
An introduction to Dialogue writing.pptx
LDMMIA Reiki Yoga S2 L3 Vod Sample Preview
UPPER GASTRO INTESTINAL DISORDER.docx
Congenital Hypothyroidism pptx
NOI Hackathon - Summer Edition - GreenThumber.pptx
What Is Coercive Control? Understanding and Recognizing Hidden Abuse
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
Open Quiz Monsoon Mind Game Prelims.pptx
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
ACUTE NASOPHARYNGITIS. pptx
Skill Development Program For Physiotherapy Students by SRY.pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Software Engineering BSC DS UNIT 1 .pptx

introduction to php and its uses in daily

  • 2. What is PHP? •PHP is an acronym for "PHP: Hypertext Preprocessor“. •PHP is a widely-used, open source scripting language •PHP scripts are executed on the server •PHP is free to download and use. •PHP files can contain text, HTML, CSS, JavaScript, and PHP code •PHP code is executed on the server, and the result is returned to the browser as plain HTML. •PHP files have extension ".php"
  • 3. What Can PHP Do? •PHP can generate dynamic page content •PHP can create, open, read, write, delete, and close files on the server •PHP can collect form data •PHP can send and receive cookies •PHP can add, delete, modify data in your database •PHP can be used to control user-access •PHP can encrypt data
  • 4. • PHP was conceived sometime in the fall of 1994 by Rasmus Lerdorf. Early non-released versions were used on his home page to keep track of who was looking at his online resume. • The first version used by others was available sometime in early 1995 and was known as the Personal Home Page Tools. HISTORY OF PHP
  • 5. Set Up PHP on Your Own PC To run PHP code, you need the following three software on your local machine: 1.Web Server (e.g., Apache) 2.PHP (Interpreter) 3.MySQL Databases (optional) You can separately install Web Server, PHP Interpreter, and MySQL databases, but to make work easier, developers have made all in one setup packages called WAMP, LAMP, MAMP, and XAMPP, which will automatically install and set up PHP environment on your Windows, Linux or MAC machines. The official PHP website (PHP.net) has installation instructions for PHP: http://php.net/manual/en/install.php
  • 6. Basic PHP Syntax A PHP script can be placed anywhere in the document. A PHP script starts with <?php and ends with ?>: The default file extension for PHP files is ".php". A PHP file normally contains HTML tags, and some PHP scripting code.
  • 7. PHP statements end with a semicolon (;).
  • 9. PHP echo and print Statements With PHP, there are two basic ways to get output: echo and print. PHP echo and print Statements • echo and print are more or less the same. They are both used to output data to the screen. • The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.
  • 10. The PHP echo Statement The echo statement can be used with or without parentheses: echo or echo().
  • 11. The PHP print Statement The print statement can be used with or without parentheses: print or print().
  • 14. PHP Variables A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for PHP variables: •A variable starts with the $ sign, followed by the name of the variable •A variable name must start with a letter or the underscore character •A variable name cannot start with a number •A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) •Variable names are case-sensitive ($age and $AGE are two different variables)
  • 16. Variables are "containers" for storing information. Remember that PHP variable names are case-sensitive!
  • 19. PHP Variables Scope In PHP, variables can be declared anywhere in the script. The scope of a variable is the part of the script where the variable can be referenced/used. PHP has three different variable scopes: •local •global •static
  • 20. Global and Local Scope A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function:
  • 28. Difference between Server Side Scripting and Client Side Scripting Client-side Scripting •It helps work with the front end. •It is visible to the users. •The scripts are run on the client browser. •It runs on the user/client’s computer. •It depends on the browser’s version. •It doesn’t interact with the server to process data. •Client side scripting involves languages such as HTML, CSS, JavaScript. •It helps reduce the load on the server. •It is considered to be less secure in comparison to client side scripting.
  • 29. Difference between Server Side Scripting and Client Side Scripting Server-side Scripting •It helps work with the back end. •It doesn’t depend on the client. •It runs on the web server. •It helps provide a response to every request that comes in from the user/client. •This is not visible to the client side of the application. •It requires the interaction with the server for the data to be process. •Server side scripting requires languages such as PHP, ASP.net, ColdFusion, Python, Ruby on Rails. •It is considered to be a secure way of working with applications. •It can be used to customize web pages. •It can also be used to provide dynamic websites.
  • 30. PHP Loops Loops are used to execute the same block of code again and again, as long as a certain condition is true In PHP, we have the following loop types: •while - loops through a block of code as long as the specified condition is true •do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true •for - loops through a block of code a specified number of times •foreach - loops through a block of code for each element in an array
  • 41. PHP Break and Continue
  • 45. PHP Conditional Statements Very often when you write code, you want to perform different actions for different conditions. You can use conditional statements in your code to do this. In PHP we have the following conditional statements: •if statement - executes some code if one condition is true •if...else statement - executes some code if a condition is true and another code if that condition is false •if...elseif...else statement - executes different codes for more than two conditions •switch statement - selects one of many blocks of code to be executed
  • 48. PHP OOP - Access Modifiers
  • 49. PHP OOP - Access Modifiers
  • 50. PHP OOP - Access Modifiers
  • 51. PHP OOP - Access Modifiers Properties and methods can have access modifiers which control where they can be accessed. There are three access modifiers: •public - the property or method can be accessed from everywhere. This is default. •protected - the property or method can be accessed within the class and by classes derived from that class. •private - the property or method can ONLY be accessed within the class
  • 52. <?php class Fruit { public $name; public $color; public $weight; function set_name($n) { // a public function (default) $this->name = $n; } protected function set_color($n) { // a protected function $this->color = $n; } private function set_weight($n) { // a private function $this->weight = $n; } } $mango = new Fruit(); $mango->set_name('Mango'); // OK $mango->set_color('Yellow'); // ERROR $mango->set_weight('300'); // ERROR ?>
  • 60. PHP Operators Operators are used to perform operations on variables and values. PHP divides the operators in the following groups: •Arithmetic operators •Assignment operators •Comparison operators •Increment/Decrement operators •Logical operators •String operators •Array operators •Conditional assignment operators
  • 61. PHP Arithmetic Operators The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc. https://www.w3schools.com/php/php_operators.asp
  • 62. https://www.w3schools.com/php/php_operators.asp PHP Assignment Operators The PHP assignment operators are used with numeric values to write a value to a variable. The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.
  • 63. PHP Comparison Operators The PHP comparison operators are used to compare two values (number or string):