PHP Notes
PHP Notes
PHP Notes
Middle ware
o software that acts as a bridge between an operating system or database and
applications, especially on a network.
Web server
o A web server is software and hardware that uses HTTP (Hypertext Transfer Protocol)
and other protocols to respond to client requests made over the World Wide Web.
o The term web server can refer to hardware or software, or both of them working
together.
o On the hardware side, a web server is a computer that stores web server software and a
website's component files (for example, HTML documents, images, CSS stylesheets, and
JavaScript files). A web server connects to the Internet and supports physical data
interchange with other devices connected to the web.
o On the software side, a web server includes several parts that control how web users
access hosted files. At a minimum, this is an HTTP server. An HTTP server is software
that understands URLs (web addresses) and HTTP (the protocol your browser uses to
view webpages). An HTTP server can be accessed through the domain names of the
websites it stores, and it delivers the content of these hosted websites to the end user's
device.
Nginx
IIS
lighttpd
Apache Tomcat
LiteSpeed Web Server
Oracle WebLogic Server
Oracle iPlanet Web Server
Jigsaw
Apache Traffic Server
Google Web Server
IBM HTTP Server
Application server
XAMPP
WAMP
PHP Parser − In order to process PHP script instructions a parser must be installed to generate
HTML output that can be sent to the Web Browser. This tutorial will guide you how to install
PHP parser on your computer.
Languages/Tools to develop web applications.
Languages:
Java
Python
PHP
C#
Ruby
Pearl
Now is the time of Multilingual web services.
Tools:
Angular
Wordpress
React
Laravel
Bootstrap
Django etc.
And,
It is commonly used to extract data out of a database on the Web server and present it on the
Web page.
It is used to manage
o dynamic content,
o databases,
o session tracking,
o even build entire e-commerce sites.
PHP, the Characteristics of it
Simplicity.
o It has less learning curve, because it is simple and straightforward to use. Someone
familiar with C programming can easily work on PHP.
Efficiency
o It’s modules in all programming sections are considered to be very efficient.
Security
Flexibility
Familiarity
Step 1: Download
XAMPP is a release made available by the non-profit project Apache Friends. Versions
with PHP 5.5, 5.6, or 7 are available for download on the Apache Friends website.
Step 2:
Run .exe file
Once the software bundle has been downloaded, you can start the installation by
double clicking on the file with the ending .exe.
Step 3:
Deactivate any antivirus software
Step 4:
Deactivate UAC
Step 5:
Start the setup wizard
After you’ve opened the .exe file (after deactivating your antivirus program(s) and taken
note of the User Account Control, the start screen of the XAMPP setup wizard should
appear automatically. Click on ‘Next’ to configure the installation settings.
Step 6:
Choose software components
Under ‘Select Components’, you have the option to exclude individual components of
the XAMPP software bundle from the installation. But for a full local test server, we
recommend you install using the standard setup and all available components. After
making your choice, click ‘Next’.
In the dialog window entitled 'select components', you can choose the software
components before installation
Step 7:
Choose the installation directory
In this next step, you have the chance to choose where you’d like the XAMPP software
packet to be installed. If you opt for the standard setup, then a folder with the name
XAMPP will be created under C:\ for you. After you’ve chosen a location, click ‘Next’.
For the next step, you need to select the directory where XAMPP should be installed
Step 8:
Start the installation process
Once all the aforementioned preferences have been decided, click to start the
installation. The setup wizard will unpack and install the selected components and save
them to the designated directory. This process can take several minutes in total. You can
follow the progress of this installation by keeping an eye on the green loading bar in the
middle of the screen.
According to the default settings, the selected software components are unpacked and
installed in the target folder
Step 9:
Windows Firewall blocking
Your Firewall may interrupt the installation process to block the some components of
the XAMPP. Use the corresponding check box to enable communication between the
Apache server and your private network or work network. Remember that making your
XAMPP server available for public networks isn’t recommended.
Step 10:
Complete installation
Once all the components are unpacked and installed, you can close the setup wizard by
clicking on ‘Finish’. Click to tick the corresponding check box and open the XAMPP
Control Panel once the installation process is finished.
The XAMPP Control Panel also offers you various other buttons, including:
Config: allows you to configure the XAMPP as well as the individual components
Netstat: shows all running processes on the local computer
Shell: opens a UNIX shell
Explorer: opens the XAMPP folder in Windows Explorer
Services: shows all services currently running in the background
Help: offers links to user forums
Quit: closes the XAMPP Control Panel
Starting modules
Individual modules can be started or stopped on the XAMPP Control Panel through the corresponding
buttons under ‘Actions’. We can see which modules have been started because their names are
highlighted green under the ‘Module’ title.
If a module can’t be started as a result of an error, you’ll be informed of this straight away in red font. A
detailed error report can help you identify the cause of the issue.
Setting up XAMPP
Configuring port
Data Types:
String
Integer
Float (floating point numbers - also called double)
Boolean
Array
Object
NULL
Resource
example:
a) $var=TRUE;
b) $gender="Male";
2. integer:
example:
$a = 123; var_dump($a); echo "<br>";
$b = -123; var_dump($b); echo "<br>";
3. float
a) Unlike integer, it can hold numbers with a fractional or decimal point,
b) including a negative or positive sign.
example: $n1 = 19.34;
4. string
a) It holds letters or any alphabets, numbers, and even special characters.
Examples:
a. $aa = 'PHP string type';
b. $message = "PHP data types";
Syntax:
array(value1, value2, value3, etc.)
Syntax:
array(key=>value,key=>value,key=>value,…..)
Examples:
<?php
$nm = Array("Arvind","Kamal","Jakir","Shradha");
echo $nm[1];
$age = Array(1,2,3,4,5,6);
echo $age[3];
$ter= Array(1=>"Bihar",2=>"MP",3=>"UP",4=>"AP");
echo $ter[4];
$mx=Array("GOA","DELHI","Bihar","Bihar"=>"Patna","U
P"=>"Lakhnow","MP"=>"Bhopal");
echo $mx["UP"];
$points=Array("Ajay"=>Array("studies"=>12,"Sports",=
>15),"Vijay" =>Array("studies"=>31,"Sports"=>12));
echo $points['Ajay']['studies'];
?>
The count() function returns the number of elements in an array.
sizeof($arr): returns the size of the array or the number of data
elements stored in the array.
array_merge($arr1, $arr2)
array_values($arr)
array_keys($arr)
array_pop($arr)
array_push($arr, $val)
sort($arr)
array_flip($arr)
array_reverse($arr)
Echo/print/var_dump
echo is a statement, which is used to display the output.
The echo() function is not actually a function, so you are not required to
use parentheses with it.
In order to output one or more strings, we can use echo statement.
Anything that can be displayed to the browser using echo statement,
such as string, numbers, variables values, the results of
expressions, etc.
It is required to use parenthesis if you want to use more than one
parameter.
<?php
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
echo array($a);// returns Array
echo "<br>";
print_r($a); // returns what check this;
echo "<br>";
var_dump($a);
echo"<br>"."----------------------------","<br>";
$b=11;
echo $b."<br>";
print $b."<br>";
print_r($b)."<br>";
var_dump($b) .”<br>” ;
$name(“Ajay”,”Vijay”,”Kamal”,”Jayesh”,”Arvind”,”Ranjeet” );
?>
Array once again.
1. $season=array("summer","winter","spring","autumn");
A. $season[0]="summer";
B. $season[1]="winter";
C. $season[2]="spring";
D. $season[3]="autumn";
<?php
$season[0]="summer";
$season[1]="winter";
$season[2]="spring";
$season[3]="autumn";
echo "Season are: $season[0], $season[1], $season[2] and $season[3]";
?>
Declaring:One way of doing this in associative array
1. $salary["amit "]="350000";
2. $salary["sumit "]="450000";
3. $salary["Kartik"]="200000";
1. $salary["amit"]="350000";
2. $salary["sumit"]="450000";
3. $salary["kaif"]="200000";
Operators
Their precedence and assosiativity:
*, /, % operators have equal precedence.
+ , - operators have equal precedence.
*, / , % have a higher precedence than + , -.
Left Associativity
Left associativity occurs when an expression is evaluated from left to
right.
100 / 10 * 10 is treated as (100 / 10) * 10
Right Associativity
o Arithmetic Operators
o + Addition $a + $b Sum of operands
o - Subtraction $a - $b Difference of operands
o * Multiplication $a * $b Product of operands
o / Division $a / $b Quotient of operands
o % Modulus $a % $b Remainder of operands
o ** Exponentiation $a ** $b $a raised to the power $b
o Assignment Operators
o Bitwise Operators
o Comparison Operators
o Incrementing/Decrementing Operators
o Logical Operators
o String Operators
o Array Operators
o Type Operators
o Execution Operators
o = Assign $a = $b
The value of right operand is assigned to the left operand.
o += Add then Assign $a += $b
Addition same as $a = $a + $b
o -= Subtract then Assign $a -= $b
Subtraction same as $a = $a - $b
o *= Multiply then Assign $a *= $b
Multiplication same as $a = $a * $b
o /= Divide then Assign
(quotient) $a /= $b Find quotient same as $a = $a / $b
o %= Divide then Assign
(remainder) $a %= $b Find remainder same as $a = $a % $b
* Comparision Operator:
Multiply both operands
A * B will give 200 == Checks if the value of
two operands are equal or
/ not, if yes then condition
Divide numerator by de- becomes true.
numerator (A == B) is not true.
B / A will give 2
!= Checks if the value of
% two operands are equal or
Modulus Operator and not, if values are not equal
remainder of after an integer then condition becomes true.
division (A != B) is true.
B % A will give 0
> Checks if the value of
++ left operand is greater than
the value of right operand, if operands are non zero then
yes then condition becomes condition becomes true.
true. (A or B) is true.
(A > B) is not true.
&& Called Logical AND
< Checks if the value of operator. If both the
left operand is less than the operands are non zero then
value of right operand, if yes condition becomes true.
then condition becomes true. (A && B) is true.
(A < B) is true.
|| Called Logical OR
>= Checks if the value of Operator. If any of the two
left operand is greater than or operands are non zero then
equal to the value of right condition becomes true.
operand, if yes then condition (A || B) is true.
becomes true.
(A >= B) is not true. ! Called Logical NOT
Operator. Use to reverses the
<= Checks if the value of logical state of its operand. If
left operand is less than or a condition is true then
equal to the value of right Logical NOT operator will
operand, if yes then condition make false.
becomes true. !(A && B) is false.
(A <= B) is true.
Assignment Operator:
Logical Operator = Simple assignment
operator, Assigns values from
and Called Logical AND right side operands to left
operator. If both the side operand
operands are true then C = A + B will assign value of
condition becomes true. A + B into C
(A and B) is true.
+= Add AND assignment
or Called Logical OR operator, It adds right
Operator. If any of the two operand to the left operand
and assign the result to left C *= A is equivalent to C = C
operand *A
C += A is equivalent to C = C
+A /= Divide AND assignment
operator, It divides left
-= Subtract AND operand with the right
assignment operator, It operand and assign the result
subtracts right operand from to left operand
the left operand and assign C /= A is equivalent to C = C /
the result to left operand A
C -= A is equivalent to C = C -
A %= Modulus AND
assignment operator, It takes
*= Multiply AND modulus using two operands
assignment operator, It and assign the result to left
multiplies right operand with operand
the left operand and assign C %= A is equivalent to C = C
the result to left operand %A
Array Operator:
1) + a+b Union Union of a and b.
2) == a==b Equality TRUE if a and b ,same key/value pairs.
3) === a===b Identity TRUE if a and b have the same key/value
pairs in the same order and of the same types.
4) != a!=b Inequality TRUE if aisnotequaltob.
5) <> a<>b Inequality TRUE if aisnotequaltob.
6) !== a!==b Non-identity TRUE if aisnotidenticaltob.
String operator
.
.=
$a = "Hello ";
$b = $a . "World!";
Now $b = "Hello World!"
$a = "Hello ";
$a .= "World!";
now $a = "Hello World!"
?>