100% found this document useful (1 vote)
1K views

Web Based Application Using PHP (22619) : Mrs Priya Ramesh Rangdal (Zade)

The document discusses the PHP programming language. It provides information on PHP syntax, variables, data types, and objects. Some key points include: - PHP is a server-side scripting language commonly used to create dynamic web applications. It allows embedding PHP code into HTML. - PHP variables start with a $, can be any valid name, and data types are determined by value (no need for declarations). Common data types are strings, integers, floats, booleans, arrays, and objects. - PHP supports object-oriented programming with classes and objects that inherit properties and methods from their classes. Objects are instantiated from classes.

Uploaded by

Akash jape
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views

Web Based Application Using PHP (22619) : Mrs Priya Ramesh Rangdal (Zade)

The document discusses the PHP programming language. It provides information on PHP syntax, variables, data types, and objects. Some key points include: - PHP is a server-side scripting language commonly used to create dynamic web applications. It allows embedding PHP code into HTML. - PHP variables start with a $, can be any valid name, and data types are determined by value (no need for declarations). Common data types are strings, integers, floats, booleans, arrays, and objects. - PHP supports object-oriented programming with classes and objects that inherit properties and methods from their classes. Objects are instantiated from classes.

Uploaded by

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

Web based application

using PHP(22619)
Mrs Priya Ramesh Rangdal(zade)
Google classroom

 tycm google classroom name- tycm(wbp)


 Code - 26qdjbp
 https://classroom.google.com/c/MzIzNDEyNDkyNTY3?
cjc=26qdjbp
Google classroom

 Tyco google classroom name-tyco(wbp)


 Code - nqfnfhx
 https://classroom.google.com/c/MzIzNDEyNDkyNjAz?
cjc=nqfnfhx
Some facts about PHP
 PHP was developed by Rasmus Lerdorf in 1995 and is later being developed as an open-source. PHP group
now manages the implementation of PHP.

 PHP has many syntaxes similar to C, Java, and Perl, and has many unique features and specific functions.

 PHP page is a file with a .php extension can contain a combination of HTML Tags and PHP scripts.

 PHP recursive acronym for PHP(Hypertext Preprocessor):  HyperText means, text containing all sorts of
web markups, PreProcessor means all of the HyperText is processed first and then the result is sent as pure
HTML to the web browser. A client cannot see the PHP source code because it is preprocessed and interpreted.

 PHP is Server-side scripting language: Server-side scripting means that the PHP code is processed on the web
server rather than the client machine.

 PHP supports many databases (MySQL and PHP combination is widely used).

 PHP is an open-source scripting language.

 PHP is free to download and use.


What you can do with php

 PHP is used to create web applications, and some of the most


popular web applications like Facebook, Yahoo, Wikipedia,
Twitter, WordPress have all been developed in PHP. And you can
also develop the next big thing using PHP.
Adantages of PHP

 PHP works on many operating systems such as Linux, Windows, Mac OS X.


 PHP is FREE to download from the official PHP resource: php.net
 PHP supports many databases like MySQL, MS SQL, Oracle, Sybase, PostgreSQL,
and many others.
 PHP can dynamically generate HTML, PDF, Flash, Text, CSV, XML and many
others.
 Coding in PHP is easy and fast, so it takes less time to build an application.
 Many good PHP frameworks like Zend, Codeigniter, and Laravel are available for
PHP.
 Many web hosting options are available at a fair price for PHP.
 With PHP, code deployment is very easy.
 Substantial PHP community support, and many tutorials and sample programs are
available online.
The PHP syntax

 PHP is designed to work with HTML, so you can easily write and embed PHP code
with HTML. A PHP code block begins with <?php tag and ends with ?> tag.
 Syntax:
<?php //your php code goes here
?>
PHP with Html

 echo is a command in PHP for writing output data to the browser,


and at the end of each PHP statement we require to write
a ; (semicolon) as you see in the below example code. Otherwise,
if you write another statement, then PHP will report a syntax error.
example

 <html>
 <title>Hello World program in PHP</title>
 <body>
 <? php echo "Hello World";
 ?>
 </body>
 </html>
 To run this PHP program, you need to write above code in any text
editor and save it to your web server under www directory with
a .php extension.
 Once it's done, start the server and go to localhost and type in the
path of your file, i.e., http://localhost/HelloWorld.php
Comments in PHP

 The PHP interpreter ignores the comment block; it can be used anywhere in the
program to add info about program or code block, which can be helpful for the
programmer to understand the code easily in the future.
 In PHP, we can use // or # to make a single-line comment, and /* and */ to
make a large comment block.
 Example:
 <html> <body>
 <?php
 // This is single line commented text, and
 # This is another single line commented text
 /* This is a Multi-lines comment block area *
 /?> </body> </html>
 https://www.youtube.com/watch?v=tlfVuqTQvx8
PHP variables

 Variables are the identifier of the memory location, which used to


save data temporarily for later use in the program.
 The purpose of variables is to store data in memory for later use.
Unlike PHP Constants which do not change during the program
execution, variables value may change during execution. If you
declare a variable in PHP, that means you are asking to the
operating system of web server for reserve a piece of memory with
that variable name.
Variable defination and
initialization
 We can make any variable types, like numbers, text strings, and arrays. All variables in PHP
start with a $ dollar sign, and the value can be assigned by using the = assignment operator.
 Example:
 <?php 
 $me = "I am David";
 echo $me;
 $num = 24562;
 echo $num;
 $name = "David";  //Valid variable name $_name = "Alex";  //Valid variable name
$1name = "Jhon";  //Invalid variablename, starts with a number
 ?> 
Variable defination and
initialization
 PHP Variables are case sensitive, variables always defined with a
$, and they must start with an underscore or a letter (no number).
 In PHP, unlike other languages, variables do not have to be
declared before assigning a value.
 You also don't require to declare data types, because PHP
automatically converts variable to data types depends upon its
value.
There are some rules on choosing
variables:
 Variable names must begin with a letter or underscore.
 The variable name can only contain alphanumeric characters and
underscore such as (a-z, A-Z, 
0-9 and _ ).
 The variable name can not contents space.
PHP variable variables

 In PHP, it is also possible to create so-called variable variables. That is


a variable whose name is contained in another variable. For example:
 Example:
 <?php 
 $name = "me";
 $$name = "Hello";
 echo $me; // Displays Hello
 ?>
A technique similar to variable variables can also
be used to hold function names inside a variable:

 <?php 
 function testFunction() 
 {
 echo "It works.";
 }
 $funct = "testFunction"; $funct(); // will call testFunction();
 ?>
 Variable of variables are very potent, and variable should be used with
care because it can make complicated to understand and document
your code, but also because of their improper use may lead to critical
security issues
PHP data types

 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

 PHP String
 A string is a sequence of characters, like "Hello world!".
 A string can be any text inside quotes. You can use single or double quotes:
 Example
 <?php
$x = "Hello world!";
$y = 'Hello world!';

echo $x;
echo "<br>";
echo $y;
?>
 Output:
 Hello world!
Hello world!
PHP Integer

 An integer data type is a non-decimal number between


-2,147,483,648 and 2,147,483,647.
 Rules for integers:
 An integer must have at least one digit
 An integer must not have a decimal point
 An integer can be either positive or negative
 Integers can be specified in: decimal (base 10), hexadecimal (base
16), octal (base 8), or
binary (base 2) notation
 In the following example $x is an integer. The PHP var_dump() function returns the
data type and value:
 Example
 <?php
$x = 5985;
var_dump($x);
?>
 Output
int(5985)
PHP Float
 A float (floating point number) is a number with a decimal point or a number in
exponential form.
 In the following example $x is a float. The PHP var_dump() function returns the data
type and value:
 Example
 <?php
$x = 10.365;
var_dump($x);
?>
 Output:
 float(10.365)
PHP Boolean

 A Boolean represents two possible states: TRUE or FALSE.


 $x = true;
$y = false;
 Booleans are often used in conditional testing.
PHP Array

 PHP Array
 An array stores multiple values in one single variable.
 In the following example $cars is an array. The PHP var_dump()
function returns the data type and value:
 Example
 <?php
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
?>
PHP objects

 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.
 Let's assume we have a class named Car. A Car can have properties like
model, color, etc. We can define variables like $model, $color, and so on, to
hold the values of these properties.
 When the individual objects (Volvo, BMW, Toyota, etc.) are created, they
inherit all the properties and behaviors from the class, but each object will
have different values for the properties.
 If you create a __construct() function, PHP will automatically call this
function when you create an object from a class.
example
 <?php
class Car {
  public $color;
  public $model;
  public function __construct($color, $model) {
    $this->color = $color;
    $this->model = $model;
  }
  public function message() {
    return "My car is a " . $this->color . " " . $this->model . "!";
 }
}

$myCar = new Car("black", "Volvo");
echo $myCar -> message();
echo "<br>";
$myCar = new Car("red", "Toyota");
echo $myCar -> message();
?>
 Output
 My car is a black Volvo!
My car is a red Toyota!
PHP null value
 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.
 Tip: If a variable is created without a value, it is automatically assigned a value of
NULL.
 Variables can also be emptied by setting the value to NULL:
 Example
 <?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
 Output
 NULL
PHP Resource

 The special resource type is not an actual data type. It is the


storing of a reference to functions and resources external to PHP.
 A common example of using the resource data type is a database
call.
PHP operators

 Operators are used to perform operations on variables and values.


 PHP divides the operators in the following groups:
 Arithmetic operators
 Assignment operators
 Comparison operators
 Increment/Decrement operators
 Logical operators
 String operators
 Array operators
 Conditional assignment operators
PHP Arithmetic Operators
Operator Name Example Result Show
it
+ Addition $x + $y Sum of $x and $y Try it »

- Subtraction $x - $y Difference of $x and $y Try it »

* Multiplication $x * $y Product of $x and $y Try it »

/ Division $x / $y Quotient of $x and $y Try it »

% Modulus $x % $y Remainder of $x divided by Try it »


$y
** Exponentiation $x ** $y Result of raising $x to the Try it »
$y'th power
 PHP Assignment Operators
 The PHP assignment operators are used with numeric values to write a value to a
variable.
 The basic assignment operator in PHP is "=". It means that the left operand gets set to
the value of the assignment expression on the right.

Assignm Same as... Description Show


ent it
x=y x=y The left operand gets set to the value of the Try it
expression on the right »
x += y x=x+y Addition Try it
»
x -= y x=x-y Subtraction Try it
»
x *= y x=x*y Multiplication Try it
»
x /= y x=x/y Division Try it
»
x %= y x=x%y Modulus
Operator Name PHP Comparison Operators
Example Result Show it

== Equal $x == $y Returns true if $x is equal to $y Try it »

=== Identical $x === $y Returns true if $x is equal to $y, and they are of the same type Try it »

!= Not equal $x != $y Returns true if $x is not equal to $y Try it »

<> Not equal $x <> $y Returns true if $x is not equal to $y Try it »

!== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the same Try it »
type

> Greater than $x > $y Returns true if $x is greater than $y Try it »

< Less than $x < $y Returns true if $x is less than $y Try it »

>= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y Try it »

<= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y Try it »

<=> Spaceship $x <=> $y Returns an integer less than, equal to, or greater than zero,
depending on if $x is less than, equal to, or greater than $y.
Introduced in PHP 7.
PHP Increment / Decrement Operators

Operator Name Description Show it


++$x Pre-increment Increments $x by one, then returns $x Try it »
$x++ Post-increment Returns $x, then increments $x by one Try it »
--$x Pre-decrement Decrements $x by one, then returns $x Try it »
$x-- Post-decrement Returns $x, then decrements $x by one
PHP Logical Operators
and And $x and $y True if both $x Try it »
and $y are true

or Or $x or $y True if either $x Try it »


or $y is true

xor Xor $x xor $y True if either $x Try it »


or $y is true, but
not both

&& And $x && $y True if both $x Try it »


and $y are true

|| Or $x || $y True if either $x Try it »


or $y is true

! Not !$x True if $x is not


true
PHP String Operators

. Concatenation $txt1 . $txt2 Concatenation


of $txt1 and
$txt2
.= Concatenation $txt1 .= $txt2 Appends $txt2
assignment to $txt1
PHP Array Operators
+ Union $x + $y Union of $x and $y

== Equality $x == $y Returns true if $x


and $y have the
same key/value
pairs

=== Identity $x === $y Returns true if $x


and $y have the
same key/value
pairs in the same
order and of the
same types

!= Inequality $x != $y Returns true if $x is


not equal to $y

<> Inequality $x <> $y Returns true if $x is


not equal to $y

!== Non-identity $x !== $y Returns true if $x is


not identical to $y
PHP Conditional Assignment Operators

Operator Name Example Result

?: Ternary $x Returns the value of $x.


= expr1 ? e The value of $x
xpr2 : expr is expr2 if expr1 = TRUE.
3 The value of $x
is expr3 if expr1 = FALSE

?? Null coalescing $x Returns the value of $x.


= expr1 ??  The value of $x
expr2 is expr1 if expr1 exists, and is
not NULL.
If expr1 does not exist, or is
NULL, the value of $x is expr2.
Introduced in PHP 7

You might also like