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

Php

Uploaded by

absapi09
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Php

Uploaded by

absapi09
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

What is PHP

o PHP stands for Hypertext Preprocessor.


o PHP
o Object-oriented language.
o Open-source scripting language.
o Interpreted
o Server-side
o Faster than other scripting languages
o Simple and easy to learn language.
o PHP is well suited for web development.
o popular backend programming language
o loosely typed language, {automatically converts the variable to its correct data type.}

History
PHP was created by Rasmus Lerdorf in 1994 but appeared in the market in 1995.

PHP 7.4.0 is the latest version of PHP, which was released on 28 November.

Why use PHP


o It handles dynamic content, database as well as session tracking for the website.
o It can access cookies variable and also set cookies.
o It helps to encrypt the data and apply validation.
o PHP supports several protocols such as HTTP, POP3, SNMP, LDAP,
IMAP, and many more.
o Using PHP language, you can control the user to access some pages of
your website.
o As PHP is easy to install and set up, this is the main reason why PHP is the best
language to learn.
o 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
PHP is very popular language because of its simplicity and open source. There
are some important features of PHP given below:
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.

o HTML
o CSS
o JavaScript
o Ajax
o XML and JSON
o jQuery

Prerequisite
Before learning PHP, you must have the basic knowledge of HTML,
CSS, and JavaScript. So, learn these technologies for better implementation of
PHP.

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.

Audience
Our PHP tutorial is designed to help beginners and professionals. This PHP
tutorial will help those who are unaware about the concepts of PHP but have
basic knowledge of computer programming.

Problem
We assure you that you will not find any problem in this PHP tutorial. But if there
is any mistake or error, please post the error in the contact form.
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:

AMP For
WAMP Windows
LAMP Linux
MAMP Mac
SAMP Solaris
FAMP FreeBSD
XAMPP (Cross, Apache, MySQL, PHP, Perl)
for Cross Platform: It includes some
other components too such as
FileZilla, OpenSSL, Webalizer,
Mercury Mail, etc.

Installation of XAMPP

Step 1: Search for xampp to


download the XAMPP
server according to your
window requirement.
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.

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.
Note: PHP statements ends with semicolon (;).
All PHP code goes between the php tag. It starts with <?php and ends with ?>.
The syntax of PHP tag is given below:

1. <?php
2. //your code here
3. ?>
Let's see a simple PHP example where we are writing some text using PHP echo
command.

File: first.php

1. <!DOCTYPE>
2. <html>
3. <body>
4. <?php
5. echo "<h2>Hello First PHP</h2>";
6. ?>
7. </body>
8. </html>
Output:

Hello First PHP

How to run PHP programs in XAMPP


How to run PHP programs in XAMPP PHP is a. 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.

For example - p1.php.

As I'm using window, and my XAMPP server is installed in D drive. So, the path
for the htdocs directory will be "D:\xampp\htdocs".
PHP program runs on a web browser such as - Chrome, Internet Explorer,
Firefox, etc. Below some steps are given to run the PHP programs.

Step 1: Create a simple PHP program like hello world.

1. <?php
2. echo "Hello World!";
3. ?>
Step 2: Save the file with hello.php name in the htdocs folder, which resides
inside the xampp folder.

Note: PHP program must be saved in the htdocs folder, which resides inside
the xampp folder, where you installed the XAMPP. Otherwise it will generate
an error - Object not found.
Step 3: Run the XAMPP server and start the Apache and MySQL.

Step 4: Now, open the web browser and type


localhost http://localhost/hello.php on your browser window.

Step 5: The output for the above hello.php program will be shown as the
screenshot below:

Most of the time, PHP programs run as a web server module. However, PHP can
also be run on CLI (Command Line Interface).
Language Work Return Function Info Example
Construct any
value
echo display the Nothing Not We can pass multiple strings separated by a comma (,) in echo. <?php
output echo "Hello by PHP echo";
?>
Echo is faster than the print statement.

print display the 1 Not print can be used with or without parentheses. <?php
output. print "Hello by PHP print ";
print ("Hello by PHP print()");
Using print, we cannot pass multiple arguments.
?>

print is slower than the echo statement.

$ Declare variable Nothing Not do not need to declare the data types of the variables. <?php
$str="hello string";
$x=200;
 Contain A-z, 0-9, _
$y=44.6;
echo "string is: $str <br/>";
 Start with A-z, _ echo "integer is: $x <br/>";
echo "float is: $y <br/>";
 No space ?>

 Case-sensitive

Local declared within a A variable declaration outside the function with the same name is <?php
variable function completely different function local_var()
{
$num = 45;
variables cannot be accessed outside the function
echo "Local variables value
is: ". $num;
local variable has higher priority than the global variable }
local_var();
?>
Global declared outside These variables can be accessed anywhere in the program. <?php
variable the function
use the GLOBAL keyword before the variable. $name = "Sanaya
Sharma"; //Global Variable
Or $GLOBALS
function global_var()

global $name;

echo "Variable
inside the function: ". $name;

echo "</br>";

global_var();

echo "Variable
outside the function: ". $name;

?>
S Static <?php
c variable
o
function static_var()
p
e
o {
f
v static $num3 = 3;
a //static variable
ri
a
b $num4 =
l 6; //Non-static variable
e
//increment in
non-static variable

$num3++;

//increment in
static variable

$num4++;

echo "Static: " .


$num3 ."</br>";

echo "Non-static: "


.$num4 ."</br>";

//first
function call

static_var();

//second function
call

static_var();

?>
$$ <?php
$x = "abc";
$$x = 200;
echo $x."<br/>";
echo $$x."<br/>";
echo $abc;
?>
Definitions

Php Php is a server-side scripting language, which is used to design the dynamic web 1
applications with mysql database.
Hypertext Text displayed on a computer display or other electronic devices with 1
references (hyperlinks) to other text that the reader can immediately access.
Preprocessor A program that processes its input data to produce output that is used as input 1
in another program
Object-oriented Enables a system to be modelled as a set of objects which can be controlled 1
and manipulated in a modular manner.
Interpreted A language in which the implementations execute instructions directly without 1
earlier compiling a program into machine language.
Server-side Server-side scripting is a technique used in web development which involves 1
employing scripts on a web server which produces a response customized for
each user's (client's) request to the website.
Open source Freely available 1
Redistributed
Modified
Rasmus Lerdorf PHP was conceived 1

sometime in the fall of


1994 by Rasmus
Lerdorf. Early non-
released versions were
used on his home page
to keep track of who
was looking at his online
resume. The first
version used by others
was available sometime
in early 1995 and was
known as the Personal
Home Page Tools.

You might also like