The document provides information about PHP (Hypertext Preprocessor) including what a server is, different types of servers, basic PHP syntax, variables, operators, conditional statements, loops, functions, and arrays. It defines PHP as a scripting language used for web development and describes its major components. Examples are given of variables, constants, arithmetic operators, and if/else conditional statements in PHP code.
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.
3.
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);
?>
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);
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