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

Unit 1

PHP, which stands for 'PHP: Hypertext Preprocessor', is an open-source scripting language executed on the server, allowing for dynamic page content generation and database manipulation. It was created by Rasmus Lerdorf in 1994, with the first public version released in 1995. PHP scripts are typically embedded within HTML and can utilize variables, with specific rules regarding naming and scope.

Uploaded by

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

Unit 1

PHP, which stands for 'PHP: Hypertext Preprocessor', is an open-source scripting language executed on the server, allowing for dynamic page content generation and database manipulation. It was created by Rasmus Lerdorf in 1994, with the first public version released in 1995. PHP scripts are typically embedded within HTML and can utilize variables, with specific rules regarding naming and scope.

Uploaded by

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

UNIT - 1

BASICS OF PHP
What is PHP?

•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.

•PHP files can contain text, HTML, CSS, JavaScript, and PHP code

•PHP code is executed on the server, and the result is returned to the browser as plain HTML

•PHP files have extension ".php"


What Can PHP Do?

•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


COOKIES
HISTORY OF PHP
PHP was conceived 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.
Set Up PHP on Your Own PC
To run PHP code, you need the following three software on your local machine:
1.Web Server (e.g., Apache)
2.PHP (Interpreter)
3.MySQL Databases (optional)

You can separately install Web Server, PHP Interpreter, and MySQL databases, but
to make work easier, developers have made all in one setup packages
called WAMP, LAMP, MAMP, and XAMPP, which will automatically install and set up
PHP environment on your Windows, Linux or MAC machines.

The official PHP website (PHP.net) has installation instructions for PHP:
http://php.net/manual/en/install.php
Basic PHP Syntax

A PHP script can be placed anywhere in the document.


A PHP script starts with <?php and ends with ?>:

The default file extension for PHP files is ".php".


A PHP file normally contains HTML tags, and some PHP scripting code.
PHP statements end with a semicolon (;).
PHP echo and print Statements

With PHP, there are two basic ways to get output: echo and print.

PHP echo and print Statements

• echo and print are more or less the same. They are both used to output data to the screen.
• The differences are small: 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.
The PHP echo Statement

The echo statement can be used with or without parentheses: echo or echo().
The PHP print Statement

The print statement can be used with or without parentheses: print or print().
PHP Variables
A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume).
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)
Variables are "containers" for storing information.

Remember that PHP variable names are case-sensitive!


PHP Variables Scope

In PHP, variables can be declared anywhere in the


script.
The scope of a variable is the part of the script where
the variable can be referenced/used.
PHP has three different variable scopes:
•local
•global
•static
Global and Local Scope

A variable declared outside a function has a GLOBAL SCOPE


and can only be accessed outside a function:

You might also like