PHP.
PHP.
Presented By:
PREETHI V M
Assistant Professor
Department of Master of Computer Science
INTRODUCTION TO
PHP
PHP IS A SERVER SIDE SCRIPTING LANGUAGE WHICH IS USED TO CREATE
DYNAMIC WEB PAGES.
PHP
• PHP started out as a small open source project that evolved as more and more people found
out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.
• 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 is forgiving: PHP language tries to be as forgiving as possible.
• PHP Syntax is C-Like.
WHY PHP
• Simplicity
• Efficiency
• Flexibility
• Familiarity
• Security
• Open Source
• Reliability
ADVANTAGES OF PHP
• Speed
• Easy to use
• Stable
• Platform Independent
• Open Source
• Built-in database connection modules
• Powerful library support
DISADVANTAGES OF PHP
• Security
• Weak Type
• Not appropriate for big application
• Not smart to create desktop Applications.
PHP AND WEB SERVER ARCHITECTURE
• This system consists of two objects : a web browser and a web server.
• A communication link is required between them. A web browser makes a request of the
server. The server sends back a response.
• This Architecture suits a server delivering static pages well and that delivers a database
backed website.
The client/server relationship between a Web browser and Web server requires communication
WEB SERVER ARCHITECTURE
• A users Web browser issues an HTTP request for a particular web page.
• The Web Server receives the request for results. PHP retrieves the file and passes it to
the PHP engine for processing.
• The PHP engine starts parsing the script. PHP opens a connection to the MySQL server
sends on the appropriate query.
• The MySQL server receives the database query and processes it and sends the results
list of books back to the PHP engine.
PHP CAPABILITIES
• Cross Platform
• Extensions
• Easy access to the tools
• Embedding
• Anytime Support
• Flexibility
• Open Source
PHP AND HTTP ENVIRONMENT VARIABLE
• $_ENV is used to return the environment variables from the web server.
• Example: <? Php
echo $_ENV[‘username’]
?>
• There are two methods of $_ENV: putenv() and getenv()
• PHP global environment variables include: $_SERVER, $_GET ,$_FILES, $_POST,
$_COOKIE etc.
LIST OF PHP AND HTTP ENVIRONMENT VARIABLES
• PATH_INFO
• PATH_TRANSLATED
• SCRIPT_NAME
• SCRIPT_FILENAME and REQUEST_FILENAME
• URL
• SCRIPT_URL and REQUEST_URL
• REQUEST_METHOD
• QUERY_STRING
• CONTENT_TYPE
• CONTENT_LENGTH
• AUTH_TYPE
CONTD..
<?php
• A variable stores a value of any type. For example: string number, array, object, or
resource. A variable has a name and value.
• Syntax to define a variable: $variable_name=value;
• For example : $name
$Net_Sa006C
• In PHP variable declaration means setting a value to a variable.
CREATING (DECLARING) PHP VARIABLES
• <?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
Output:
Hello world!
5
10.5
VARIABLE DECLARATION:
• A variable declaration is a named memory location that contains data that may be
manipulated throughout the execution of the script.
• Variables are declared when first used in PHP. Variables in PHP are identifiers prefixed
with a dollar sign:$.
• Syntax: $variable;
PHP CONSTANTS
• A constant is an identifier (name) for a simple value. The value cannot be changed during the script.
• A valid constant name starts with a letter or underscore (no $ sign before the constant name)
Example
<!DOCTYPE html>
<html>
<body>
<?php
// case-sensitive constant name
define("GREETING", "Welcome to jss collage.com!");
echo GREETING;
?>
</body>
</html>
PHP DATA TYPES(PRIMITIVES)
• Variables can store data of different types, and different data types can do different things.
• PHP supports the following data types:
• String
• Integer
• Float (floating point numbers - also called double)
• Boolean
• Array
• Object
• NULL
• Resource
PHP STRING
echo $x;
echo "<br>";
echo $y;
?>
Output:
Hello world!
Hello world!
PHP INTEGER
• In the following example $x is an integer. The PHP var_dump() function returns the data type
and value:
<?php
$x = 5985;
var_dump($x); ?>
Output: int(5985)
PHP FLOAT
<?php $x = 10.365;
var_dump($x); ?>
OUTPUT: Float(10.365)
PHP BOOLEAN
• Example:
• Classes and objects are the two main aspects of object-oriented programming.
• A class is a template for objects, and an object is an instance of a class.
• When the individual objects are created, they inherit all the properties and behaviors from
the class, but each object will have different values for the properties.
EXAMPLE OF PHP OBJECT
class Person
Public $name = ‘ ‘;
Function name($newname)
$this-> name=$newname; } }
$p = new person();
$p->name(“preethi”);
• Null is a special data type which can have only one value: NULL.
• A variable of data type NULL is a variable that has no value assigned to it.
• Example:
<?php $x = "Hello world!";
$x = null;
var_dump($x); ?>
OUTPUT: null
THANK YOU