0% found this document useful (0 votes)
264 views

PHP Presentation

PHP is an open-source, server-side scripting language that can be used to develop dynamic web applications. It is interpreted and object-oriented. PHP code is embedded into HTML and executed on the server to create dynamic web page content. It is widely used for web development due to being easy to install, simple to learn, and supporting various databases and web servers.

Uploaded by

moses maned
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
264 views

PHP Presentation

PHP is an open-source, server-side scripting language that can be used to develop dynamic web applications. It is interpreted and object-oriented. PHP code is embedded into HTML and executed on the server to create dynamic web page content. It is widely used for web development due to being easy to install, simple to learn, and supporting various databases and web servers.

Uploaded by

moses maned
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 67

PHP

PHP is an open-source, interpreted, and object-oriented scripting


language that can be executed at the server-side. PHP is well suited for
web development. Therefore, it is used to develop web applications (an
application that executes on the server and generates the dynamic
page.)
• PHP stands for Hypertext Preprocessor.
• PHP is an interpreted language, i.e., there is no need for compilation.
• PHP is faster than other scripting languages, for example, ASP and JSP.
• PHP is a server-side scripting language, which is used to manage the
dynamic content of the website.
• PHP can be embedded into HTML.
• PHP is an object-oriented language.
• PHP is an open-source scripting language.
• PHP is simple and easy to learn language.
Why use PHP
• PHP is a server-side scripting language, which is used to design the dynamic web
applications with MySQL database.
• It handles dynamic content, database as well as session tracking for the website.
• You can create sessions in PHP.
• It can access cookies variable and also set cookies.
• It helps to encrypt the data and apply validation.
• PHP supports several protocols such as HTTP, POP3, SNMP, LDAP, IMAP, and many
more.
• Using PHP language, you can control the user to access some pages of your website.
• As PHP is easy to install and set up, this is the main reason why PHP is the best
language to learn.
• PHP can handle the forms, such as - collect the data from users using forms, save it
into the database, and return useful information to the user. For example -
Registration form.
PHP Features

• Performance:
• PHP script is executed much faster than those scripts which are written in other languages such
as JSP and ASP. PHP uses its own memory, so the server workload and loading time is
automatically reduced, which results in faster processing speed and better performance.
• Open Source:
• PHP source code and software are freely available on the web. You can develop all the versions
of PHP according to your requirement without paying any cost. All its components are free to
download and use.
• Familiarity with syntax:
• PHP has easily understandable syntax. Programmers are comfortable coding with it.
• Embedded:
• PHP code can be easily embedded within HTML tags and script.
• Platform Independent:
• PHP is available for WINDOWS, MAC, LINUX & UNIX operating system. A PHP application
developed in one OS can be easily executed in other OS also.
• Database Support:
• PHP supports all the leading databases such as MySQL, SQLite, ODBC, etc.
• Error Reporting -
• PHP has predefined error reporting constants to generate an error notice
or warning at runtime. E.g., E_ERROR, E_WARNING, E_STRICT, E_PARSE.
• Loosely Typed Language:
• PHP allows us to use a variable without declaring its datatype. It will be
taken automatically at the time of execution based on the type of data it
contains on its value.
• Web servers Support:
• PHP is compatible with almost all local servers used today like Apache,
Netscape, Microsoft IIS, etc.
• Security:
• PHP is a secure language to develop the website. It consists of multiple
layers of security to prevent threads and malicious attacks.
• Control:
• Different programming languages require long script or code, whereas
PHP can do the same work in a few lines of code. It has maximum control
over the websites like you can make changes easily whenever you want.
• A Helpful PHP Community:
• It has a large community of developers who regularly updates
documentation, tutorials, online help, and FAQs. Learning PHP from the
communities is one of the significant benefits.
• Web Development
• PHP is widely used in web development nowadays. PHP can develop
dynamic websites easily. But you must have the basic the knowledge of
following technologies for web development as well.
• HTML
• CSS
• JavaScript
• HTML - HTML is used to design static webpage.
• CSS - CSS helps to make the webpage content more effective and
attractive.
• JavaScript - JavaScript is used to design an interactive website.
Install PHP

• To install PHP, we will suggest you to install AMP (Apache, MySQL, PHP) software
stack. It is available for all operating systems. There are many AMP options available
in the market that are given below:
• WAMP for Windows
• LAMP for Linux
• MAMP for Mac
• SAMP for Solaris
• FAMP for FreeBSD
• XAMPP (Cross, Apache, MySQL, PHP, Perl) for Cross Platform: It includes some other
components too such as FileZilla, OpenSSL, Webalizer, Mercury Mail, etc.
• If you are on Windows and don't want Perl and other features of XAMPP, you should
go for WAMP. In a similar way, you may use LAMP for Linux and MAMP for
Macintosh.
• How to install XAMPP server on windows
• Step 1: Click on the below link provided to download the XAMPP
server according to your window requirement.
• https://www.apachefriends.org/download.html
Step 2: After downloading XAMPP, double click on the
downloaded file and allow XAMPP to make changes in
your system. A window will pop-up, where you have to
click on the Next button.
Step 3: Here, select the components, which you want to
install and click Next.
Step 4: Choose a folder where you want to install the XAMPP in your system and
click Next.
Step 5: Click Next and move ahead.
Step 6: XAMPP is ready to install, so click on
the Next button and install the XAMPP.
Step 7: A finish window will display after successful installation. Click
on the Finish button.
Step 8: Choose your preferred language.
Step 9: XAMPP is ready to use. Start the Apache server and MySQL and run the php program on the
localhost.
Step 10: If no error is shown, then XAMPP is
running successfully.
Install XAMPP on LinuX
Click on the below link and follow the all steps

https://www.wikihow.com/Install-XAMPP-on-Linux
Or
https://www.wikihow.com/Install-XAMPP-on-Linux
https://vitux.com/ubuntu-xampp/
https://www.youtube.com/watch?v=R5CUn5wGQGg
How to run PHP code in XAMPP
• Generally, a PHP file contains HTML tags and some PHP scripting code. It
is very easy to create a simple PHP example. To do so, create a file and
write HTML tags + PHP code and save this file with .php extension
• All PHP code goes between the php tag. It starts with <?php and ends
with ?>. The syntax of PHP tag is given below:
<?php   
//your code here  
?>  
PHP Echo

• PHP echo statement can be used to print the string, multi-line strings,
escaping characters, variable, array, etc. Some important points that
you must know about the echo statement are:
• echo is a statement, which is used to display the output.
• echo can be used with or without parentheses: echo(), and echo.
• echo does not return any value.
• We can pass multiple strings separated by a comma (,) in echo.
• echo is faster than the print statement.
• PHP print statement can be used to print the string, multi-line strings,
escaping characters, variable, array, etc. Some important points that
you must know about the echo statement are:
• print is a statement, used as an alternative to echo at many times to
display the output.
• print can be used with or without parentheses.
• print always returns an integer value, which is 1.
• Using print, we cannot pass multiple arguments.
• print is slower than the echo statement.
Difference between echo and print
echo
• echo is a statement, which is used to display the output.
• echo can be used with or without parentheses.
• echo does not return any value.
• We can pass multiple strings separated by comma (,) in echo.
• echo is faster than print statement.
print
• print is also a statement, used as an alternative to echo at many times
to display the output.
• print can be used with or without parentheses.
• print always returns an integer value, which is 1.
• Using print, we cannot pass multiple arguments.
• print is slower than echo statement.
• Let's see a simple PHP example where we are writing some text using
PHP echo command.
• File: hello.php
•   <?php      
   echo "Hello World!";  
• ?> 
How to run PHP programs in XAMPP
• PHP is a popular backend programming language. PHP programs can
be written on any editor, such as - Notepad, Notepad++,
Dreamweaver, etc. These programs save with .php extension, i.e.,
filename.php inside the htdocs folder.
• PHP program runs on a web browser such as - Chrome, Internet
Explorer, Firefox, etc. Below some steps are given to run the PHP
programs.
• Most of the time, PHP programs run as a web server module.
However, PHP can also be run on CLI (Command Line Interface).
• Open terminal or command line window.
• Goto the specified folder or directory where php files are present.
• Then we can run php code using the following command:
Php filena.php
PHP Comments
• PHP comments can be used to describe any line of code so that other developer can
understand the code easily. It can also be used to hide any code.
• PHP supports single line and multi line comments. These comments are similar to C/C++
and Perl style (Unix shell style) comments.
PHP Single Line Comments
• There are two ways to use single line comments in PHP.
• // (C++ style single line comment)
• # (Unix Shell style single line comment)
• <?php  
• // this is C++ style single line comment  
• # this is Unix Shell style single line comment  
• echo "Welcome to PHP single line comments";  
• ?>  
• PHP Multi Line Comments
• In PHP, we can comments multiple lines also. To do so, we need to enclose all lines within /* */.
Let's see a simple example of PHP multiple line comment.
• <?php  
• /* 
• Anything placed 
• within comment 
• will not be displayed 
• on the browser; 
• */  
• echo "Welcome to PHP multi line comment";  
• ?>  
Variables in PHP

• Variables are used for storing values, like text strings, numbers or arrays.
• Variables in PHP are represented by a dollar ($) sign followed by the name
of the variable. The
• As PHP is a loosely typed language, so we do not need to declare the data
types of the variables. It automatically analyzes the values and makes
conversions to its correct datatype.
• After declaring a variable, it can be reused throughout the code.
• Assignment Operator (=) is used to assign the value to a variable.
• variable name is case-sensitive.
• The correct way of setting a variable in PHP:
• $var_name = value;
Rules for declaring PHP variable:

• A variable must start with a dollar ($) sign, followed by the variable
name.
• It can only contain alpha-numeric character and underscore (A-z, 0-9, _).
• A variable name must start with a letter or underscore (_) character.
• A PHP variable name cannot contain spaces.
• One thing to be kept in mind that the variable name cannot start with a
number or special symbols.
• PHP variables are case-sensitive, so $name and $NAME both are treated
as different variable.
PHP Variable: Declaring string, integer, and float
Let's see the example to store string, integer, and float values in PHP variables.

<?php  
$str="hello string";  
$x=200;  
$y=44.6;  
echo "string is: $str <br/>";  
echo "integer is: $x <br/>";  
echo "float is: $y <br/>";  
?>  
• PHP: Loosely typed language
• PHP is a loosely typed language, it means PHP automatically converts
the variable to its correct data type.
PHP Variable Scope

• The scope of a variable is defined as its range in the program under


which it can be accessed. In other words, "The scope of a variable is
the portion of the program within which it is defined and can be
accessed."
PHP has three types of variable scopes:
• Local variable
• Global variable
• Static variable
Local variable

• The variables that are declared within a function are called local
variables for that function. These local variables have their scope only
in that particular function in which they are declared. This means that
these variables cannot be accessed outside the function, as they have
local scope.
• A variable declaration outside the function with the same name is
completely different from the variable declared inside the function.
Let's understand the local variables with the help of an example:
Global variable

The global variables are the variables that are declared outside the
function. These variables can be accessed anywhere in the program. To
access the global variable within a function, use the GLOBAL keyword
before the variable. However, these variables can be directly accessed
or used outside the function without any keyword. Therefore there is
no need to use any keyword to access a global variable outside the
function.
Static variable

• It is a feature of PHP to delete the variable, once it completes its


execution and memory is freed. Sometimes we need to store a
variable even after completion of function execution. Therefore,
another important feature of variable scoping is static variable. We
use the static keyword before the variable to define a variable, and
this variable is called as static variable.
• Static variables exist only in a local function, but it does not free its
memory after the program execution leaves the scope
PHP Constants
• PHP constants are name or identifier that can't be changed during the
execution of the script. PHP constants can be defined by 2 ways:
• Using define() function
• Using const keyword
• Constants are similar to the variable except once they defined, they
can never be undefined or changed. They remain constant across the
entire program. PHP constants follow the same PHP variable rules.
For example, it can be started with a letter or underscore only.
Conventionally, PHP constants should be defined in uppercase letters.
PHP constant: define()
• Use the define() function to create a constant. It defines constant at run time.
Let's see the syntax of define() function in PHP.
• define(name, value, case-insensitive)  
• name: It specifies the constant name.
• value: It specifies the constant value.
• case-insensitive: Specifies whether a constant is case-insensitive. Default value
is false. It means it is case sensitive by default.
constant1.php
<?php  
define("MESSAGE","Hello This is PHP");   Output: Hello This is PHP
echo MESSAGE;  
?>  
Create a constant with case-insensitive name
<?php    
define("MESSAGE"," Hello This is PHP ",true);//not case sensitive    
echo MESSAGE, "</br>";    
echo message;    
?>  
Output
Hello This is PHP
Hello This is PHP
<?php  
define("MESSAGE","Hello JavaTpoint PHP",false);//case sensitive  
echo MESSAGE;  
echo message;  
?>  
const keyword
PHP introduced a keyword const to create a constant. The const
keyword defines constants at compile time.
<?php  
const MESSAGE="Hello const by JavaTpoint PHP";  
echo MESSAGE;  
?>  
Constant() function
• There is another way to print the value of constants using constant()
function instead of using the echo statement.
<?php      
 define("MSG", "JavaTpoint");  
echo MSG, "</br>";  
echo constant("MSG");  
//both are similar  
?>  
PHP Data Types

• PHP data types are used to hold different types of data or values. PHP supports 8 primitive data types
that can be categorized further in 3 types:
1.Scalar Types (predefined)
2.Compound Types (user-defined)
3.Special Types
• PHP Data Types: Scalar Types
• It holds only single value. There are 4 scalar data types in PHP.
1.boolean
2.integer
3.float
4.string
• PHP Data Types: Compound Types
• It can hold multiple values. There are 2 compound data types in PHP.
1.array
2.object
• PHP Data Types: Special Types
There are 2 special data types in PHP.
1.resource
2.NULL
PHP Boolean
Booleans are the simplest data type works like switch. It holds only two
values: TRUE (1) or FALSE (0). It is often used with conditional
statements. If the condition is correct, it returns TRUE otherwise
FALSE.
PHP Integer
Integer means numeric data with a negative or positive sign. It holds only
whole numbers, i.e., numbers without fractional part or decimal points.
Rules for integer:
• An integer can be either positive or negative.
• An integer must not contain decimal point.
• Integer can be decimal (base 10), octal (base 8), or hexadecimal (base
16).
• The range of an integer must be lie between 2,147,483,648 and
2,147,483,647 i.e., -2^31 to 2^31.
PHP Float
A floating-point number is a number with a decimal point. Unlike
integer, it can hold numbers with a fractional or decimal point, including
a negative or positive sign.
PHP String
• A string is a non-numeric data type. It holds letters or any alphabets, numbers,
and even special characters.
• String values must be enclosed either within single quotes or in double
quotes. But both are treated differently. To clarify this, see the example below:
<?php   
 $school = “RCA";  
//both single and double quote statements will treat different  
echo "Hello $school ";  
echo "</br>";  
echo 'Hello $school ';  
?>  
PHP Array
An array is a compound data type. It can store multiple values of same
data type in a single variable.
PHP object
Objects are the instances of user-defined classes that can store both
values and functions. They must be explicitly declared.
PHP Resource
• Resources are not the exact data type in PHP. Basically, these are used
to store some function calls or references to external PHP
resources. For example - a database call. It is an external resource.
• This is an advanced topic of PHP, so we will discuss it later in detail
with examples.
PHP Null
• Null is a special data type that has only one value: NULL. There is a
convention of writing it in capital letters as it is case sensitive.
• The special type of data type NULL defined a variable with no value.
<?php   
$nl = NULL;  
echo $nl;   //it will not give any output  
?>  
PHP Operators
• PHP Operator is a symbol used to perform operations on operands. In
simple words, operators are used to perform operations on variables or
values.
PHP Operators can be categorized in following forms:
 Arithmetic Operators
 Assignment Operators
 Bitwise Operators
 Comparison Operators
 Incrementing/Decrementing Operators
 Logical Operators
 String Operators
 Array Operators
 Type Operators
 Execution Operators
 Error Control Operators
Arithmetic Operators
• The PHP arithmetic operators are used to perform common arithmetic
operations such as addition, subtraction, etc. with numeric values.
Assignment Operators
• The assignment operators are used to assign value to different
variables. The basic assignment operator is "=".
Bitwise Operators
• The bitwise operators are used to perform bit-level operations on
operands. These operators allow the evaluation and manipulation of
specific bits within the integer.
Comparison Operators
• Comparison operators allow comparing two values, such as number or
string. Below the list of comparison operators are given:

You might also like