SlideShare a Scribd company logo
PHP:
Hypertext
Preprocessor
Content
 What is Server?
 Types of servers.
 Basic PHP.
 Syntax of PHP.
 Variables.
 Operators.
 Conditional Statements.
 Loops.
 PHP Function.
 PHP Array & It‟s types.
4 Basic PHP
What is Server ?
 In a technical sense, a server is an instance of a computer
program that accepts and responds to requests made by
another program, known as a client.
 Less formally, any device that runs server software could be
considered a server as well.
 Servers are used to manage network resources.
 For example, a user may setup a server to control access to
a network, send/receive e-mail, manage print jobs, or host
a website.
What is Server ? (cont.)
 Some servers are committed to a specific task, often referred to as
dedicated.
 As a result, there are a number of dedicated server categories, like print
servers, file servers, network servers, and database servers.
 However, many servers today are shared servers which can take on the
responsibility of e-mail, DNS, FTP, and even multiple websites in the case of
a web server.
 Because they are commonly used to deliver services that are required
constantly, most servers are never turned off.
 Consequently, when servers fail, they can cause the network users and
company many problems.
 To alleviate these issues, servers are commonly high-end computers setup
to be fault tolerant.
Examples(types) of servers
 The following list contains various server types.
1. Application server
2. Blade server
3. Cloud server
4. Database server
5. Dedicated server
6. File server
7. Mail server
8. Print server
9. Proxy server
10. Standalone server
11. Web server
Application server
 The application server is a framework, an environment where applications
can run, no matter what they are or what functions they perform.
 An application server can be used to develop and run web-based
applications.
 There are a number of different types of application servers, including
Java, PHP and .NET Framework application servers.
Blade
 A blade may refer to any of the following:
1. When referring to a network router, switch, server, or other network
device, a blade(also known as an expansion module) is a
hardware component that can be installed into a chassis.
2. When talking about servers, a blade, blade server, or a high density
server is one rack mount unit that is capable of holding dozens of
different servers.
Cloud computing
 Cloud computing is a term used to describe services provided
over a network by a collection of remote servers.
 This abstract “cloud” of computers provides massive, distributed
storage and processing power, which can be accessed by any
Internet-connected device running a web browser.
 Examples of cloud services
 Amazon Web Services (AWS)
 Dashlane
 Google App Engine
 Google Calendar
 Microsoft OneDrive
 Etc..
Database Server
 A database server is a computer system that provides other
computers with services related to accessing and retrieving
data from a database.
 Access to the database server may occur via a “front end”
running locally a user‟s machine (e.g., phpMyAdmin), or
“back end” running on the database server itself, accessed
by remote shell.
 After the information within the database is retrieved it is
outputted to the user requesting the data.
Dedicated server
 A server that is hosted by a company and only allows one company to lease
and access it is called a dedicated server.
 It is “dedicated” to the one client and is not shared with any other clients.
 Dedicated servers usually allow the client to choose what operating system is
installed on it and what type of hardware.
 In most cases, the hosting company performs all or most of the maintenance on
the dedicated server. This includes:
 operating system updates
 updates to any installed applications
 monitoring of the server and applications
 firewall maintenance
 intrusion detection and prevention
 data backups
 disaster recovery
File server
 A file server is a computer on a network that is used to
provide users on a network with access to files.
Mail server
 A remote or central computer that holds electronic mail (e-mail)
messages for clients on a network is called a mail server.
 A mail server is similar to the post office, where mail is stored and
sorted before being sent to its final destination.
 When the user requests his or her e-mail, contact is established with
the mail server, which then delivers all stored to the client‟s computer.
Print server
 Computer or standalone device responsible for managing
one or more printers on a network.
 Because of the load required for a print job, a print
server does not need to be a fast computer.
 The picture is an example of a wireless standalone print
server from Cisco.
Proxy server
 A proxy is a computer server or software program that is part of
the gateway server or another computer that separates a local
network from outside networks.
 A proxy server will cache all pages accessed through the network
allowing users who may want to visit that same page to load it faster
and reduce the networks bandwidth.
 When a page is accessed that is not in the proxy server‟s cache, the
proxy server accesses the page using its own IP address, caches the
page, and forward it to the user.
SAS
 SAS may refer to any of the following:
 Short for Serial Attached SCSI, SASis a serial transmission replacement
for the parallel SCSI. SAS is an improvement of regular SCSI in that it
allow up to 128 devices to be connected at the same time with
transmission speeds of 3.0 Gb/s. SAS devices have two data ports and
can communicate with both SCSI and SATA.
 Short for Standalone Server, SASis a server that does not rely on any
other servers or services.
 Abbreviation sometimes used to describe SUPER Anti Spyware.
Web server
 Computer or collection of computers used to deliver web pages
and other content to multiple users.
 Below are some examples of web server software.
 Apache HTTP Server
 Apache Tomcat
 Microsoft IIS
 LAMP
 FastCGI
 LIGHTTPD
 XAMP
What is PHP(7.3)??
 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
 It is powerful enough to be at the core of the biggest blogging system on the
web (WordPress)!
 It is deep enough to run the largest social network (Facebook)!
Components of PHP
 To develop and run PHP Web pages three vital components need to be installed.
 Web Server
 Database
 PHP Parser
HTML v/s PHP
 How it differs from HTML
 differentiates PHP with client-side language like HTML is, PHP codes are executed on
server whereas HTML codes are directly rendered on the browser. PHP codes are first
executed on the server and then the result is returned to the browser.
Characteristics of PHP
 Simplicity
 Efficiency
 Security
 Flexibility
 Familiarity
 Inter-operable(php in html, html in php)
 PHP is whitespace insensitive
 PHP is case sensitive
Application of PHP
 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
Basic PHP
 Basic PHP Syntax

 // This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
Variables in PHP
 Creating (Declaring) PHP Variables
 <?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
 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)
Constant in PHP
 There is no need to write a dollar sign ($) before a constant, where as in Variable
one has to write a dollar sign.
 Constants cannot be defined by simple assignment, they may only be defined
using the define() function.
 Constants may be defined and accessed anywhere without regard to variable
scoping rules.
 Once the Constants have been set, may not be redefined or undefined.
 <?php
define("MINSIZE", 50);
echo MINSIZE;
?>
Example of Variable
 <?php
$txt = “How are you?";
echo “Hello, " . $txt . "!";
?>
 Output: Hello, How are you?
 <?php
$txt = “How are you?";
echo “Hello, $txt !";
?>
 Output: ?
PHP Variables Scope
 PHP has three different variable scopes:
 local
 global
 static
 PHP The global Keyword
 global $x, $y;
 $GLOBALS[index] Array
 $GLOBALS['y'],
 $GLOBALS[„x']
 PHP The static Keyword
 static $x;
PHP echo & Print
 The PHP echo Statement
 echo or echo()
 The PHP print Statement
 print or print()
 echo has no return value while print has a return value of 1 so it can be used in
expressions.
 echo can take multiple parameters (although such usage is rare) while print can
take one argument.
 echo is marginally faster than print.
PHP Data Types
 PHP supports the following data types:
 String
 Integer
 Float (floating point numbers - also called double)
 Boolean
 Array
 Object
 NULL
 Resource
PHP Class & Object
 <?php
class Car {
function Car() {
$this->model = “Ferrari";
}
}
// create an object
$herbie = new Car();
// show object properties
echo $herbie->model;
?>
PHP 5 Strings
 Length of a String
 strlen("Hello world!"); // outputs 12
 Number of Words in a String
 str_word_count("Hello world!"); // outputs 2
 Reverse a String
 strrev("Hello world!"); // outputs !dlrow olleH
 Search For a Specific Text Within a String
 strpos("Hello world!", "world"); // outputs 6
 Replace Text Within a String
 str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly!
PHP Constants
 define(name, value, case-insensitive)
 name: Specifies the name of the constant
 value: Specifies the value of the constant
 case-insensitive: Specifies whether the constant name should be case-insensitive.
Default is false
 <?php
define("GREETING", "Welcome to CHARUSAT!");
echo GREETING;
?>
PHP Operators
 PHP divides the operators in the following groups:
 Arithmetic operators
 Assignment operators
 Comparison operators
 Increment/Decrement operators
 Logical operators
 String operators
 Array operators
PHP Arithmetic Operators
Operator Name Example Result
+ Addition $x + $y Sum of $x and $y
- Subtraction $x - $y Difference of $x and $y
* Multiplication $x * $y Product of $x and $y
/ Division $x / $y Quotient of $x and $y
% Modulus $x % $y Remainder of $x divided by $y
** Exponentiation $x ** $y Result of raising $x to the $y'th power
(Introduced in PHP 5.6)
PHP Assignment Operators
Assignment Same as... Description
x = y x = y The left operand gets set to the value of the
expression on the right
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus
PHP Comparison Operators
Operator Name Example Result
== Equal $x == $y Returns true if $x is equal to $y
=== Identical $x === $y Returns true if $x is equal to $y,
and they are of the same type
!= Not equal $x != $y Returns true if $x is not equal to $y
<> Not equal $x <> $y Returns true if $x is not equal to $y
!== Not identical $x !== $y Returns true if $x is not equal to $y,
or they are not of the same type
> Greater than $x > $y Returns true if $x is greater than $y
< Less than $x < $y Returns true if $x is less than $y
>= Greater than
or equal to
$x >= $y Returns true if $x is greater than
or equal to $y
<= Less than
or equal to
$x <= $y Returns true if $x is less than
or equal to $y
PHP Increment / Decrement
Operators
Operator Name Description
++$x Pre-increment Increments $x by one, then returns $x
$x++ Post-increment Returns $x, then increments $x by one
--$x Pre-decrement Decrements $x by one, then returns $x
$x-- Post-decrement Returns $x, then decrements $x by one
PHP Logical Operators
Operator Name Example Result
and And $x and $y True if both $x and $y are true
or Or $x or $y True if either $x or $y is true
xor Xor $x xor $y True if either $x or $y is true, but not both
&& And $x && $y True if both $x and $y are true
|| Or $x || $y True if either $x or $y is true
! Not !$x True if $x is not true
PHP String Operators
Operator Name Example Result
. Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2
.= Concatenation
assignment
$txt1 .= $txt2 Appends $txt2 to $txt1
PHP Array Operators
Operator Name Example Result
+ Union $x + $y Union of $x and $y
== Equality $x == $y Returns true if $x and $y have the
same key/value pairs
=== Identity $x === $y Returns true if $x and $y have the
same key/value pairs in the same
order and of the same types
!= Inequality $x != $y Returns true if $x is not equal to $y
<> Inequality $x <> $y Returns true if $x is not equal to $y
!== Non-identity $x !== $y Returns true if $x is not identical to $y
PHP Conditional Statements
 In PHP we have the following conditional statements:
 if statement - executes some code only if a specified condition is true
 if...else statement - executes some code if a condition is true and another code if the
condition is false
 if...elseif....else statement - specifies a new condition to test, if the first condition is false
 switch statement - selects one of many blocks of code to be executed
If...elseif…else Statement
 <?php
$t = 12;
if ($t < "10") {
echo "Have a good morning!";
} elseif ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
Switch Statement
 <?php
$favcolor = "red";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, or green!";
}
?>
PHP Loops
 In PHP, we have the following looping statements:
 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
The PHP while Loop
 <?php
$x = 1;
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
The PHP do...while Loop
 <?php
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>
The PHP for Loops
 The PHP for Loop
 <?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
 The PHP foreach Loop
 <?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
PHP Functions
 PHP User Defined Functions
 A function is a block of statements that can be used repeatedly in a program.
 A function will not execute immediately when a page loads.
 A function will be executed by a call to the function.
 <?php
function writeMsg() {
echo "Hello world!";
}
writeMsg(); // call the function
?>
PHP Function Arguments
 <?php
function familyName($fname, $year) {
echo "$fname Stilinski Born in $year <br>";
}
familyName("Hege", "1975");
familyName("Stale", "1978");
familyName("Kai Jim", "1983");
?>
PHP Default Argument Value
 <?php
function setHeight($minheight = 50) {
echo "The height is : $minheight <br>";
}
setHeight(350);
setHeight(); // will use the default value of 50
setHeight(135);
setHeight(80);
?>
PHP Functions - Returning
values
 <?php
function sum($x, $y) {
$z = $x + $y;
return $z;
}
echo "5 + 10 = " . sum(5, 10) . "<br>";
echo "7 + 13 = " . sum(7, 13) . "<br>";
echo "2 + 4 = " . sum(2, 4);
?>
PHP Arrays
 In PHP, there are three types of arrays:
 Indexed arrays - Arrays with a numeric index
 Associative arrays - Arrays with named keys
 Multidimensional arrays - Arrays containing one or more arrays
PHP Indexed Arrays
 <?php
$cars = array("Volvo", "BMW", "Toyota");
OR
$cars[0] = “Volvo”;
$cars[1] = “BMW”;
$cars[2] = “Toyota”;
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>
 The Length of an Array - The count() Function
 count($cars);
PHP Indexed Arrays
 <?php
$cars = array("Volvo", "BMW", "Toyota");
OR
$cars[0] = “Volvo”;
$cars[1] = “BMW”;
$cars[2] = “Toyota”;
$arrlength = count($cars);
for($x = 0; $x < $arrlength; $x++) {
echo $cars[$x];
echo "<br>";
}
?>
PHP Associative Arrays
 <?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years old.";
?>
 <?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
foreach($age as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
PHP Multidimensional Arrays
 <?php
$contacts = array(
array( "name" => "Peter Parker", "email" => "peterparker@mail.com", ),
array( "name" => "Clark Kent", "email" => "clarkkent@mail.com", ),
array( "name" => "Harry Potter", "email" => "harrypotter@mail.com", ) );
echo "Peter Parker's Email-id is: " . $contacts[0]["email"];
print_r($contact);
var_dump($cities);
PHP Multidimensional Arrays
 $favorites = array(
"Dave Punk" => array(
"mob" => "5689741523",
"email" => "davepunk@gmail.com",
),
"Dave Punk" => array(
"mob" => "2584369721",
"email" => "montysmith@gmail.com",
),
"John Flinch" => array(
"mob" => "9875147536",
"email" => "johnflinch@gmail.com",
)
);
keys = array_keys($favorites);
for($i = 0; $i < count($favorites); $i++)
{
echo $keys[$i] . "n";
foreach($favorites[$keys[$i]] as $key => $value) {
echo $key . " : " . $value . "n";
}
echo "n";
}
PHP Include & Require
 The include (or require) statement takes all the text/code/markup that exists in
the specified file and copies it into the file that uses the include statement.
 It is possible to insert the content of one PHP file into another PHP file
 The include and require statements are identical, except upon failure:
 require will produce a fatal error (E_COMPILE_ERROR) and stop the script
 include will only produce a warning (E_WARNING) and the script will continue
PHP Include & Require
 Footer.php
 <?php
echo "<p>Copyright &copy; 2017-" . date("Y") . " charusat.ac.in</p>";
?>
 Index.php/home.php/dept.php
 <html>
<body>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php include 'footer.php';?>
</body>
</html>
PHP Handling Form input
 GET v/s POST Method
 $_GET, $_POST, $_REQUEST

More Related Content

What's hot (20)

PPT
Web servers
webhostingguy
 
ODP
PHP Training: Module 1
hussulinux
 
PPT
Apache Web Server Setup 4
Information Technology
 
PPTX
Web Server - Internet Applications
sandra sukarieh
 
PPT
Apache ppt
Sanmuga Nathan
 
PDF
Apache web server tutorial for linux
Sahad Sali
 
PPTX
Apache server configuration & optimization
Gokul Muralidharan
 
PPT
Apache
Rathan Raj
 
ODP
web server
nava rathna
 
PPT
Securing Your Web Server
manugoel2003
 
ODP
Linux Apache Php Mysql Lamp1273
hussulinux
 
PPT
Ajax
NIRMAL FELIX
 
ODP
Web Server-Side Programming Techniques
guest8899ec02
 
PDF
Apache Web server Complete Guide
webhostingguy
 
PPTX
ASP.NET WEB API Training
Chalermpon Areepong
 
PPTX
Apache web server
zrstoppe
 
PPT
Web Servers: Architecture and Security
george.james
 
PPT
Apache
NIRMAL FELIX
 
PDF
Apache Tutorial
Guru99
 
PDF
Web server
Touhid Arastu
 
Web servers
webhostingguy
 
PHP Training: Module 1
hussulinux
 
Apache Web Server Setup 4
Information Technology
 
Web Server - Internet Applications
sandra sukarieh
 
Apache ppt
Sanmuga Nathan
 
Apache web server tutorial for linux
Sahad Sali
 
Apache server configuration & optimization
Gokul Muralidharan
 
Apache
Rathan Raj
 
web server
nava rathna
 
Securing Your Web Server
manugoel2003
 
Linux Apache Php Mysql Lamp1273
hussulinux
 
Web Server-Side Programming Techniques
guest8899ec02
 
Apache Web server Complete Guide
webhostingguy
 
ASP.NET WEB API Training
Chalermpon Areepong
 
Apache web server
zrstoppe
 
Web Servers: Architecture and Security
george.james
 
Apache
NIRMAL FELIX
 
Apache Tutorial
Guru99
 
Web server
Touhid Arastu
 

Similar to 4 Basic PHP (20)

PPT
Php unit i
prakashvs7
 
PPTX
PHP Hypertext Preprocessor
adeel990
 
PPTX
Chapter onehsfhjfgjhdjhdhfsGfhghsgasg (2).pptx
berihun18
 
PPTX
Introduction to webprogramming using PHP and MySQL
anand raj
 
PPTX
Web Application Development using PHP Chapter 1
Mohd Harris Ahmad Jaal
 
ODP
PHP BASIC PRESENTATION
krutitrivedi
 
PDF
PHP Basics
Roohul Amin
 
PPTX
Introduction to PHP.pptx
MarianJRuben
 
PPTX
PHP language presentation
Annujj Agrawaal
 
PDF
Introduction to php
KIRAN KUMAR SILIVERI
 
PPT
PHP and MySQL
bmani
 
PPT
PHP
sometech
 
PDF
PHP in Web development and Applications.pdf
VinayVitekari
 
PPTX
introduction to php and its uses in daily
vishal choudhary
 
PPTX
Php unit i
BagavathiLakshmi
 
PPT
Php1
mohamed yusuf
 
PPT
slidesharenew1
truptitasol
 
PPT
345345
truptitasol
 
PPT
ssfsd fsdf ds f
truptitasol
 
PPT
test
truptitasol
 
Php unit i
prakashvs7
 
PHP Hypertext Preprocessor
adeel990
 
Chapter onehsfhjfgjhdjhdhfsGfhghsgasg (2).pptx
berihun18
 
Introduction to webprogramming using PHP and MySQL
anand raj
 
Web Application Development using PHP Chapter 1
Mohd Harris Ahmad Jaal
 
PHP BASIC PRESENTATION
krutitrivedi
 
PHP Basics
Roohul Amin
 
Introduction to PHP.pptx
MarianJRuben
 
PHP language presentation
Annujj Agrawaal
 
Introduction to php
KIRAN KUMAR SILIVERI
 
PHP and MySQL
bmani
 
PHP in Web development and Applications.pdf
VinayVitekari
 
introduction to php and its uses in daily
vishal choudhary
 
Php unit i
BagavathiLakshmi
 
slidesharenew1
truptitasol
 
345345
truptitasol
 
ssfsd fsdf ds f
truptitasol
 
Ad

More from Jalpesh Vasa (15)

PDF
Object Oriented PHP - PART-1
Jalpesh Vasa
 
PDF
Object Oriented PHP - PART-2
Jalpesh Vasa
 
PDF
5. HTML5
Jalpesh Vasa
 
PDF
4.4 PHP Session
Jalpesh Vasa
 
PDF
4.3 MySQL + PHP
Jalpesh Vasa
 
PDF
4.2 PHP Function
Jalpesh Vasa
 
PDF
4.1 PHP Arrays
Jalpesh Vasa
 
PDF
3.2.1 javascript regex example
Jalpesh Vasa
 
PDF
3.2 javascript regex
Jalpesh Vasa
 
PDF
3. Java Script
Jalpesh Vasa
 
PDF
3.1 javascript objects_DOM
Jalpesh Vasa
 
PDF
2 introduction css
Jalpesh Vasa
 
PDF
1 web technologies
Jalpesh Vasa
 
PDF
Remote Method Invocation in JAVA
Jalpesh Vasa
 
PDF
Kotlin for android development
Jalpesh Vasa
 
Object Oriented PHP - PART-1
Jalpesh Vasa
 
Object Oriented PHP - PART-2
Jalpesh Vasa
 
5. HTML5
Jalpesh Vasa
 
4.4 PHP Session
Jalpesh Vasa
 
4.3 MySQL + PHP
Jalpesh Vasa
 
4.2 PHP Function
Jalpesh Vasa
 
4.1 PHP Arrays
Jalpesh Vasa
 
3.2.1 javascript regex example
Jalpesh Vasa
 
3.2 javascript regex
Jalpesh Vasa
 
3. Java Script
Jalpesh Vasa
 
3.1 javascript objects_DOM
Jalpesh Vasa
 
2 introduction css
Jalpesh Vasa
 
1 web technologies
Jalpesh Vasa
 
Remote Method Invocation in JAVA
Jalpesh Vasa
 
Kotlin for android development
Jalpesh Vasa
 
Ad

Recently uploaded (20)

PPTX
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PDF
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
PPTX
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PDF
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
PPTX
Introduction to Probability(basic) .pptx
purohitanuj034
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
Virus sequence retrieval from NCBI database
yamunaK13
 
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
Introduction to Probability(basic) .pptx
purohitanuj034
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
Basics and rules of probability with real-life uses
ravatkaran694
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 

4 Basic PHP

  • 2. Content  What is Server?  Types of servers.  Basic PHP.  Syntax of PHP.  Variables.  Operators.  Conditional Statements.  Loops.  PHP Function.  PHP Array & It‟s types.
  • 4. What is Server ?  In a technical sense, a server is an instance of a computer program that accepts and responds to requests made by another program, known as a client.  Less formally, any device that runs server software could be considered a server as well.  Servers are used to manage network resources.  For example, a user may setup a server to control access to a network, send/receive e-mail, manage print jobs, or host a website.
  • 5. What is Server ? (cont.)  Some servers are committed to a specific task, often referred to as dedicated.  As a result, there are a number of dedicated server categories, like print servers, file servers, network servers, and database servers.  However, many servers today are shared servers which can take on the responsibility of e-mail, DNS, FTP, and even multiple websites in the case of a web server.  Because they are commonly used to deliver services that are required constantly, most servers are never turned off.  Consequently, when servers fail, they can cause the network users and company many problems.  To alleviate these issues, servers are commonly high-end computers setup to be fault tolerant.
  • 6. Examples(types) of servers  The following list contains various server types. 1. Application server 2. Blade server 3. Cloud server 4. Database server 5. Dedicated server 6. File server 7. Mail server 8. Print server 9. Proxy server 10. Standalone server 11. Web server
  • 7. Application server  The application server is a framework, an environment where applications can run, no matter what they are or what functions they perform.  An application server can be used to develop and run web-based applications.  There are a number of different types of application servers, including Java, PHP and .NET Framework application servers.
  • 8. Blade  A blade may refer to any of the following: 1. When referring to a network router, switch, server, or other network device, a blade(also known as an expansion module) is a hardware component that can be installed into a chassis. 2. When talking about servers, a blade, blade server, or a high density server is one rack mount unit that is capable of holding dozens of different servers.
  • 9. Cloud computing  Cloud computing is a term used to describe services provided over a network by a collection of remote servers.  This abstract “cloud” of computers provides massive, distributed storage and processing power, which can be accessed by any Internet-connected device running a web browser.  Examples of cloud services  Amazon Web Services (AWS)  Dashlane  Google App Engine  Google Calendar  Microsoft OneDrive  Etc..
  • 10. Database Server  A database server is a computer system that provides other computers with services related to accessing and retrieving data from a database.  Access to the database server may occur via a “front end” running locally a user‟s machine (e.g., phpMyAdmin), or “back end” running on the database server itself, accessed by remote shell.  After the information within the database is retrieved it is outputted to the user requesting the data.
  • 11. Dedicated server  A server that is hosted by a company and only allows one company to lease and access it is called a dedicated server.  It is “dedicated” to the one client and is not shared with any other clients.  Dedicated servers usually allow the client to choose what operating system is installed on it and what type of hardware.  In most cases, the hosting company performs all or most of the maintenance on the dedicated server. This includes:  operating system updates  updates to any installed applications  monitoring of the server and applications  firewall maintenance  intrusion detection and prevention  data backups  disaster recovery
  • 12. File server  A file server is a computer on a network that is used to provide users on a network with access to files.
  • 13. Mail server  A remote or central computer that holds electronic mail (e-mail) messages for clients on a network is called a mail server.  A mail server is similar to the post office, where mail is stored and sorted before being sent to its final destination.  When the user requests his or her e-mail, contact is established with the mail server, which then delivers all stored to the client‟s computer.
  • 14. Print server  Computer or standalone device responsible for managing one or more printers on a network.  Because of the load required for a print job, a print server does not need to be a fast computer.  The picture is an example of a wireless standalone print server from Cisco.
  • 15. Proxy server  A proxy is a computer server or software program that is part of the gateway server or another computer that separates a local network from outside networks.  A proxy server will cache all pages accessed through the network allowing users who may want to visit that same page to load it faster and reduce the networks bandwidth.  When a page is accessed that is not in the proxy server‟s cache, the proxy server accesses the page using its own IP address, caches the page, and forward it to the user.
  • 16. SAS  SAS may refer to any of the following:  Short for Serial Attached SCSI, SASis a serial transmission replacement for the parallel SCSI. SAS is an improvement of regular SCSI in that it allow up to 128 devices to be connected at the same time with transmission speeds of 3.0 Gb/s. SAS devices have two data ports and can communicate with both SCSI and SATA.  Short for Standalone Server, SASis a server that does not rely on any other servers or services.  Abbreviation sometimes used to describe SUPER Anti Spyware.
  • 17. Web server  Computer or collection of computers used to deliver web pages and other content to multiple users.  Below are some examples of web server software.  Apache HTTP Server  Apache Tomcat  Microsoft IIS  LAMP  FastCGI  LIGHTTPD  XAMP
  • 18. What is PHP(7.3)??  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  It is powerful enough to be at the core of the biggest blogging system on the web (WordPress)!  It is deep enough to run the largest social network (Facebook)!
  • 19. Components of PHP  To develop and run PHP Web pages three vital components need to be installed.  Web Server  Database  PHP Parser HTML v/s PHP  How it differs from HTML  differentiates PHP with client-side language like HTML is, PHP codes are executed on server whereas HTML codes are directly rendered on the browser. PHP codes are first executed on the server and then the result is returned to the browser.
  • 20. Characteristics of PHP  Simplicity  Efficiency  Security  Flexibility  Familiarity  Inter-operable(php in html, html in php)  PHP is whitespace insensitive  PHP is case sensitive
  • 21. Application of PHP  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
  • 22. Basic PHP  Basic PHP Syntax   // This is a single-line comment # This is also a single-line comment /* This is a multiple-lines comment block that spans over multiple lines */
  • 23. Variables in PHP  Creating (Declaring) PHP Variables  <?php $txt = "Hello world!"; $x = 5; $y = 10.5; ?>  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)
  • 24. Constant in PHP  There is no need to write a dollar sign ($) before a constant, where as in Variable one has to write a dollar sign.  Constants cannot be defined by simple assignment, they may only be defined using the define() function.  Constants may be defined and accessed anywhere without regard to variable scoping rules.  Once the Constants have been set, may not be redefined or undefined.  <?php define("MINSIZE", 50); echo MINSIZE; ?>
  • 25. Example of Variable  <?php $txt = “How are you?"; echo “Hello, " . $txt . "!"; ?>  Output: Hello, How are you?  <?php $txt = “How are you?"; echo “Hello, $txt !"; ?>  Output: ?
  • 26. PHP Variables Scope  PHP has three different variable scopes:  local  global  static  PHP The global Keyword  global $x, $y;  $GLOBALS[index] Array  $GLOBALS['y'],  $GLOBALS[„x']  PHP The static Keyword  static $x;
  • 27. PHP echo & Print  The PHP echo Statement  echo or echo()  The PHP print Statement  print or print()  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.
  • 28. PHP Data Types  PHP supports the following data types:  String  Integer  Float (floating point numbers - also called double)  Boolean  Array  Object  NULL  Resource
  • 29. PHP Class & Object  <?php class Car { function Car() { $this->model = “Ferrari"; } } // create an object $herbie = new Car(); // show object properties echo $herbie->model; ?>
  • 30. PHP 5 Strings  Length of a String  strlen("Hello world!"); // outputs 12  Number of Words in a String  str_word_count("Hello world!"); // outputs 2  Reverse a String  strrev("Hello world!"); // outputs !dlrow olleH  Search For a Specific Text Within a String  strpos("Hello world!", "world"); // outputs 6  Replace Text Within a String  str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly!
  • 31. PHP Constants  define(name, value, case-insensitive)  name: Specifies the name of the constant  value: Specifies the value of the constant  case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false  <?php define("GREETING", "Welcome to CHARUSAT!"); echo GREETING; ?>
  • 32. PHP Operators  PHP divides the operators in the following groups:  Arithmetic operators  Assignment operators  Comparison operators  Increment/Decrement operators  Logical operators  String operators  Array operators
  • 33. PHP Arithmetic Operators Operator Name Example Result + Addition $x + $y Sum of $x and $y - Subtraction $x - $y Difference of $x and $y * Multiplication $x * $y Product of $x and $y / Division $x / $y Quotient of $x and $y % Modulus $x % $y Remainder of $x divided by $y ** Exponentiation $x ** $y Result of raising $x to the $y'th power (Introduced in PHP 5.6)
  • 34. PHP Assignment Operators Assignment Same as... Description x = y x = y The left operand gets set to the value of the expression on the right x += y x = x + y Addition x -= y x = x - y Subtraction x *= y x = x * y Multiplication x /= y x = x / y Division x %= y x = x % y Modulus
  • 35. PHP Comparison Operators Operator Name Example Result == Equal $x == $y Returns true if $x is equal to $y === Identical $x === $y Returns true if $x is equal to $y, and they are of the same type != Not equal $x != $y Returns true if $x is not equal to $y <> Not equal $x <> $y Returns true if $x is not equal to $y !== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the same type > Greater than $x > $y Returns true if $x is greater than $y < Less than $x < $y Returns true if $x is less than $y >= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y <= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y
  • 36. PHP Increment / Decrement Operators Operator Name Description ++$x Pre-increment Increments $x by one, then returns $x $x++ Post-increment Returns $x, then increments $x by one --$x Pre-decrement Decrements $x by one, then returns $x $x-- Post-decrement Returns $x, then decrements $x by one
  • 37. PHP Logical Operators Operator Name Example Result and And $x and $y True if both $x and $y are true or Or $x or $y True if either $x or $y is true xor Xor $x xor $y True if either $x or $y is true, but not both && And $x && $y True if both $x and $y are true || Or $x || $y True if either $x or $y is true ! Not !$x True if $x is not true
  • 38. PHP String Operators Operator Name Example Result . Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2 .= Concatenation assignment $txt1 .= $txt2 Appends $txt2 to $txt1
  • 39. PHP Array Operators Operator Name Example Result + Union $x + $y Union of $x and $y == Equality $x == $y Returns true if $x and $y have the same key/value pairs === Identity $x === $y Returns true if $x and $y have the same key/value pairs in the same order and of the same types != Inequality $x != $y Returns true if $x is not equal to $y <> Inequality $x <> $y Returns true if $x is not equal to $y !== Non-identity $x !== $y Returns true if $x is not identical to $y
  • 40. PHP Conditional Statements  In PHP we have the following conditional statements:  if statement - executes some code only if a specified condition is true  if...else statement - executes some code if a condition is true and another code if the condition is false  if...elseif....else statement - specifies a new condition to test, if the first condition is false  switch statement - selects one of many blocks of code to be executed
  • 41. If...elseif…else Statement  <?php $t = 12; if ($t < "10") { echo "Have a good morning!"; } elseif ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>
  • 42. Switch Statement  <?php $favcolor = "red"; switch ($favcolor) { case "red": echo "Your favorite color is red!"; break; case "blue": echo "Your favorite color is blue!"; break; case "green": echo "Your favorite color is green!"; break; default: echo "Your favorite color is neither red, blue, or green!"; } ?>
  • 43. PHP Loops  In PHP, we have the following looping statements:  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
  • 44. The PHP while Loop  <?php $x = 1; while($x <= 5) { echo "The number is: $x <br>"; $x++; } ?>
  • 45. The PHP do...while Loop  <?php $x = 1; do { echo "The number is: $x <br>"; $x++; } while ($x <= 5); ?>
  • 46. The PHP for Loops  The PHP for Loop  <?php for ($x = 0; $x <= 10; $x++) { echo "The number is: $x <br>"; } ?>  The PHP foreach Loop  <?php $colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>"; } ?>
  • 47. PHP Functions  PHP User Defined Functions  A function is a block of statements that can be used repeatedly in a program.  A function will not execute immediately when a page loads.  A function will be executed by a call to the function.  <?php function writeMsg() { echo "Hello world!"; } writeMsg(); // call the function ?>
  • 48. PHP Function Arguments  <?php function familyName($fname, $year) { echo "$fname Stilinski Born in $year <br>"; } familyName("Hege", "1975"); familyName("Stale", "1978"); familyName("Kai Jim", "1983"); ?>
  • 49. PHP Default Argument Value  <?php function setHeight($minheight = 50) { echo "The height is : $minheight <br>"; } setHeight(350); setHeight(); // will use the default value of 50 setHeight(135); setHeight(80); ?>
  • 50. PHP Functions - Returning values  <?php function sum($x, $y) { $z = $x + $y; return $z; } echo "5 + 10 = " . sum(5, 10) . "<br>"; echo "7 + 13 = " . sum(7, 13) . "<br>"; echo "2 + 4 = " . sum(2, 4); ?>
  • 51. PHP Arrays  In PHP, there are three types of arrays:  Indexed arrays - Arrays with a numeric index  Associative arrays - Arrays with named keys  Multidimensional arrays - Arrays containing one or more arrays
  • 52. PHP Indexed Arrays  <?php $cars = array("Volvo", "BMW", "Toyota"); OR $cars[0] = “Volvo”; $cars[1] = “BMW”; $cars[2] = “Toyota”; echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "."; ?>  The Length of an Array - The count() Function  count($cars);
  • 53. PHP Indexed Arrays  <?php $cars = array("Volvo", "BMW", "Toyota"); OR $cars[0] = “Volvo”; $cars[1] = “BMW”; $cars[2] = “Toyota”; $arrlength = count($cars); for($x = 0; $x < $arrlength; $x++) { echo $cars[$x]; echo "<br>"; } ?>
  • 54. PHP Associative Arrays  <?php $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); echo "Peter is " . $age['Peter'] . " years old."; ?>  <?php $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); foreach($age as $x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>"; } ?>
  • 55. PHP Multidimensional Arrays  <?php $contacts = array( array( "name" => "Peter Parker", "email" => "[email protected]", ), array( "name" => "Clark Kent", "email" => "[email protected]", ), array( "name" => "Harry Potter", "email" => "[email protected]", ) ); echo "Peter Parker's Email-id is: " . $contacts[0]["email"]; print_r($contact); var_dump($cities);
  • 56. PHP Multidimensional Arrays  $favorites = array( "Dave Punk" => array( "mob" => "5689741523", "email" => "[email protected]", ), "Dave Punk" => array( "mob" => "2584369721", "email" => "[email protected]", ), "John Flinch" => array( "mob" => "9875147536", "email" => "[email protected]", ) ); keys = array_keys($favorites); for($i = 0; $i < count($favorites); $i++) { echo $keys[$i] . "n"; foreach($favorites[$keys[$i]] as $key => $value) { echo $key . " : " . $value . "n"; } echo "n"; }
  • 57. PHP Include & Require  The include (or require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.  It is possible to insert the content of one PHP file into another PHP file  The include and require statements are identical, except upon failure:  require will produce a fatal error (E_COMPILE_ERROR) and stop the script  include will only produce a warning (E_WARNING) and the script will continue
  • 58. PHP Include & Require  Footer.php  <?php echo "<p>Copyright &copy; 2017-" . date("Y") . " charusat.ac.in</p>"; ?>  Index.php/home.php/dept.php  <html> <body> <h1>Welcome to my home page!</h1> <p>Some text.</p> <p>Some more text.</p> <?php include 'footer.php';?> </body> </html>
  • 59. PHP Handling Form input  GET v/s POST Method  $_GET, $_POST, $_REQUEST