0% found this document useful (0 votes)
35 views27 pages

Introduction To PHP

Uploaded by

soulexiled5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views27 pages

Introduction To PHP

Uploaded by

soulexiled5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

INTRODUCTION TO

PHP

PHP Stand for:


Hyper Text Preprocessor

PHP is a Server Scripting Language, and a


powerful tool for making dynamic and
interactive web pages.
WHAT IS A PHP FILE?

 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 ,open, read ,write, delete and close files on the
server.
 PHP can collect form data.

 PHP can send and receive cookies.

 PHP can be used to control user-access.

 PHP can add, delete, modifying data in your database.

 PHP can encrypt data.


WHY PHP?

 PHP runs an various platforms(Window, Linux , Unix ,


MacOSX ,etc.)
 PHP is compatible with almost all servers used today
(Apache , IIS, etc.)
 PHP supports a wide range of database.

 PHP is free . Download it from the official PHP resource.

 PHP is easy to learn and runs efficiently on the server


side.
PHP DATA TYPES

 String
 Integer

 Float

 Boolean

 Object

 Array

 Null
DEFINITIONS AND EXAMPLES

 PHP String

A string is a sequence of characters, like


“Hello World!”.
Example:-
<?php
$x = “Hello World!”;
echo “$x”;
?>
PHP INTEGER

 An Integer data type is a non-decimal number rules for


integer.
 The PHP var_dump function returns the data type and
value.

Example:
<?php
$a = 100;
Var_dump ($a);
?>
PHP FLOAT

 A Float is a number with a decimal point or a number in


a exponential form.

Example:
<?php
$b = 29.76;
Var_dump ($b);
?>
PHP BOOLEAN

 A Boolean represent two possible states:


True
False

Example;
<?php
$a = 40;
$b = 70;
Var_dump ($a > $b);
?>
PHP ARRAY

 An Array store multiple values in one single variable.

Example:
<?php
$car = array(“Volvo”, “BMW”, “Toyota”);
Var_dump ($car);
?>
PHP OBJECT

 An object is a data which stores data and information on


how to process that data.
PHP NULL

 Null is a specific data type which can have only one


value null.
Example:
<?php
$f = “Hello World”;
$f = null;
Var_dump ($f);
?>
PHP OPERATORS

Operators are used to perform operation on variable and


values.

i. Arithmetic Operators
ii. Assignment Operators
iii. Comparison Operators
iv. Increment / Decrement Operators
v. Logical Operators
vi. String Operators
vii. Array Operators
viii. Conditional assignment Operators
PHP – THE IF STATEMENT

 The if statement executes some code if one condition is true.

Syntax :
If (condition) {
code to be executed if condition is true;
}

Example:
<?php
$a = data(“H”);
if ($a <“20”){
echo “Have a good day!”;
}
?>
PHP –THE IF—ELSE STATEMENT

 The if – else statement executes some code if one condition is true and another condition is
false.

Syntax:
If (condition){
Code to be executed if condition is true;
}else{
Code to be executed if condition is false;
}

Example:
<?php
$a = data(“H”);
if ($a <“20”){
echo “Have a good day!”;
} else{
echo “Have a bad day!”;
}
?>
PHP - THE - IF -ELSE--IF STATEMENT
The if-else--if statement executes different codes for more than one
conditions.

Example:
<?php
$a = data(“H”);
if ($a <“20”){
echo “Have a good day!”;
} else{
echo “Have a bad day!”;
}else if{
echo “Have a good night!”;
}
?>
PHP LOOPS

Often when you write code, you want the some block of
code to run over again a certain number of times , so
instead of adding several almost equal code-lines a script ,
we can use loops.

Loops are use to execute the some block code again as long
as a certain condition is true.
TYPES OF LOOPS

 While-loop: through a block of code as long as the


specified condition is true.

 Do-while-loop: through a block of code once, and then


reports the loop as long as the condition is true.

 For-each-loop: through a block of code of each element


in a array.
PHP WHILE LOOP

The while loop executes a block of code as long as the


specified is true.

Example:
<?php
$x = 1;
while ($x <=5){
echo “The number is $x <br>”;
$x++;}
?>
PHP FUNCTIONS

The real power of PHP comes from its function.

PHP has more than 1000 built-in functions,


and in addition you can create your own
custom functions.
PHP USER DEFINED FUNCTION

Beside the built-in PHP function, possible to create you


own functions.

• A function is a block of statement that can be used


repeatedly in a program.
• A function will not execute automatically when a page
loads.
• A function will be executed by a call to the function.

 NOTE: A function name must start with a letter or an


underscore. Function name are Not case –sensitive.
EXAMPLES:

<?php
Function write Msg() {
echo “Hello World!”;
}
Write Msg();//call the function
?>

Tip: Give the function a name that reflects what the


function does!
PHP FUNCTIONS ARGUMENTS

Information can be passed to function through arguments . An


arguments is just like a variable arguments are specified after the
function name, inside the parenthesis . You can add many arguments
as you want , just separate then with a comma.

Example:
<?php
Function family Name($ fname) {
echo “$ fname Refsnes,<br>”;
}
Family Name(“Jenni”);
Family Name(“Hege”);
Family Name(“Stale”);
?>
PHP GLOBAL VARIABLE SUPER GLOBES
Super global were introduction in PHP 4.1.0, and are built-
in variable that are always available in all scape.

Some predefined variables in PHP are super globes”,


which means that they are always accessible, regardless of
scope- and you can access than from any function , class
or file without having to do anything special.
PHP SUPER GLOBAL VARIABLES
 $GLOBALS
 $_SERVER

 $_REQUEST

 $_POST

 $_GET

 $_FILES

 $_ENV

 $_COOKIE

 $_SESSION
GET VS POST

 Both Get & Post create an array (e.g. array (key1=>


value1, key2=> value2, key3=> value3…)). This array
holds key / values pairs, where keys are the name of the
form controls and values are the input data from the user.

 Both Get & Post are treated as $_GET AND $_POST,


there are super global, which means that they are always
accessible , regardless of scope- and you can access then
from any function , class or file without having to do
anything special.
WHEN TO USE GET?

Information sent from a form with the GET method is


visible to everyone (all variable names and values are
displays in the URL).
GET also has limits to the amount of information to send .
The limitation is about 2000 characters. However , because
the variable are displayed in the URL it is possible to
bookmark the page.

GET may be used for sending non-sensitive data .

You might also like