SlideShare a Scribd company logo
PHP TUTORIAL
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP is a server scripting language, and a
powerful tool for making dynamic and interactive
Web pages.
PHP is a widely-used, free, and efficient
alternative to competitors such as Microsoft's
ASP.
PHP: Hypertext Preprocessor
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
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
What is PHP?
• PHP runs on various platforms (Windows, Linux,
Unix, Mac OS X, etc.)
• PHP is compatible with almost all servers used
today (Apache, IIS, etc.)
• PHP supports a wide range of databases
• PHP is free. Download it from the official PHP
resource: www.php.net
• PHP is easy to learn and runs efficiently on the
server side
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
Basic PHP Syntax
• A PHP script can be placed anywhere in the document.
• A PHP script starts with <?php and ends with ?>
• <!DOCTYPE html>
<html>
<body>
<h1>PHP TUTORIAL</h1>
<?php
echo “YCCE NAGPUR”;
?>
</body>
</html>
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
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) BY
PRATIK TAMBEKAR
HEMANT HINGAVE
Basic PHP Syntax
<!DOCTYPE html>
<html>
<body>
<?php
// This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
// You can also use comments to leave out parts of a code line
$x = 5 /* + 15 */ + 5;
echo $x;
?>
</body>
</html>
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP is a Loosely Typed Language
• In the example above, notice that we did not
have to tell PHP which data type the variable
is.
• PHP automatically converts the variable to the
correct data type, depending on its value.
• In other languages such as C, C++, and Java,
the programmer must declare the name and
type of the variable before using it.
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
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
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP The global Keyword
• The global keyword is used to access a global variable from
within a function.
• To do this, use the global keyword before the variables
<?php
$x = 5;
$y = 10;
function myTest() {
global $x, $y;
$y = $x + $y;
}
myTest();
echo $y;
?>
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP The static Keyword
• <?php
function myTest() {
static $x = 0;
echo $x;
$x++;
}
myTest();
myTest();
myTest();
?>
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
The PHP echo Statement
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with
multiple parameters.";
?>
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
The PHP print Statement
<?php
$txt1 = "Learn PHP";
$txt2 = “ycce.com";
$x = 5;
$y = 4;
print "<h2>$txt1</h2>";
print "Study PHP at $txt2<br>";
print $x + $y;
?> BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Data Types
• PHP supports the following data types:
• String
• Integer
• Float (floating point numbers - also called double)
• Boolean
• Array
• Object
• NULL
• Resource
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Data Types
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 = 5985;
var_dump($x);
?> BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Data Types
PHP Array:
<?php
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
?>
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Object
• An object is a data type which stores data and information
on how to process that data.
• In PHP, an object must be explicitly declared.
<?php
class Car {
function Car() {
$this->model = "VW";
}
}
// create an object
$herbie = new Car();
// show object properties
echo $herbie->model;
?> BY
PRATIK TAMBEKAR
HEMANT HINGAVE
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.
• Note: If a variable is created without a value, it is
automatically assigned a value of NULL.
Example
<?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP String Functions
Get The Length of a String:
• The PHP strlen() function returns the length of a string
(number of characters).
• The example below returns the length of the string
"Hello world!":
Example
<?php
echo strlen("Hello world!"); // outputs 12
?>
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP String Functions
Count The Number of Words in a String:
Example
<?php
echo str_word_count("Hello world!"); // outputs
2
?>
Reverse a String:
Example
<?php
echo strrev("Hello world!");
?> BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP String Functions
Search For a Specific Text Within a String:
• If a match is found, the function returns the
character position of the first match. If no
match is found, it will return FALSE.
Example
<?php
echo strpos("Hello world!", "world"); //
outputs 6
?>
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP String Functions
• Replace Text Within a String:
Example
<?php
echo str_replace("world", "Dolly", "Hello
world!"); // outputs Hello Dolly!
?>
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
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).
• Note: Unlike variables, constants are
automatically global across the entire script.
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Constants
Syntax:
define(name, value, case-insensitive)
Parameters:
• name: Specifies the name of the constant
• value: Specifies the value of the constant
• case-insensitive: Specifies whether the
constant name should be case-insensitive.
Default is false
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Constants
<?php
define(“YASHWANTRAO", "Welcome to YCCE!");
echo YASHWANTRAO;
?>
Constants are Global:
<?php
define(" YASHWANTRAO ", " Welcome to YCCE!");
function myTest() {
echo YASHWANTRAO;
}
myTest();
?>
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
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 BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Operators
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Arithmetic Operators:
PHP Operators
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Assignment Operators:
PHP Operators
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Comparison Operators:
PHP Operators
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Increment / Decrement Operators:
PHP Operators
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Logical Operators:
PHP Operators
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP String Operators:
PHP Operators
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP Array Operators:
PHP Conditional Statements
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• In PHP we have the following conditional
statements:
• if statement - executes some code only if a
specified condition is true
• if...else statement - executes some code if a
condition is true and another code if the
condition is false
• if...elseif....else statement - specifies a new
condition to test, if the first condition is false
• switch statement - selects one of many blocks of
code to be executed
PHP - The if Statement
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• The if statement is used to execute some
code only if a specified condition is true.
Syntax
if (condition)
{
code to be executed if condition is true;
}
PHP - The if...else Statement
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• Use the if....else statement to execute some
code if a condition is true and another code if
the condition is false.
Syntax:
if (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}
PHP - The if...elseif....else Statement
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• Use the if....elseif...else statement to specify a
new condition to test, if the first condition is
false.
Syntax:
if (condition) {
code to be executed if condition is true;
} elseif (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}
PHP - The switch Statement
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• Use the switch statement to select one of many blocks
of code to be executed.
Syntax:
switch (n) {
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
case label3:
code to be executed if n=label3;
break;
...
default:
code to be executed if n is different from all labels;
}
PHP Loops
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
In PHP, we have the following looping
statements:
• while - loops through a block of code as long
as the specified condition is true
• do...while - loops through a block of code
once, and then repeats the loop as long as the
specified condition is true
• for - loops through a block of code a specified
number of times
• foreach - loops through a block of code for
each element in an array
while Loop
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• The while loop executes a block of code as
long as the specified condition is true.
Syntax:
while (condition is true)
{
code to be executed;
}
do...while Loop
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• The do...while loop will always execute the
block of code once, it will then check the
condition, and repeat the loop while the
specified condition is true.
Syntax:
do {
code to be executed;
}
while (condition is true);
for Loop
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• The for loop is used when you know in
advance how many times the script should
run.
Syntax:
for (init counter; test counter; increment
counter)
{
code to be executed;
}
foreach Loop
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• The foreach loop works only on arrays, and is
used to loop through each key/value pair in an
array.
Syntax:
foreach ($array as $value)
{
code to be executed;
}
foreach Loop
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• For every loop iteration, the value of the current
array element is assigned to $value and the array
pointer is moved by one, until it reaches the last
array element.
Example:
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
PHP Functions
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP User Defined Functions
• Besides the built-in PHP functions, we can
create our own functions.
• A function is a block of statements that can be
used repeatedly in a program.
• A function will not execute immediately when
a page loads.
• A function will be executed by a call to the
function.
Create a User Defined Function in PHP
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• A user defined function declaration starts with
the word "function":
Syntax:
function functionName()
{
code to be executed;
}
• Note: A function name can start with a letter
or underscore (not a number).
Create a User Defined Function in PHP
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
Example:
<?php
function setHeight($minheight = 50) {
echo "The height is : $minheight <br>";
}
setHeight(350);
setHeight(); // will use the default value of 50
setHeight(135);
setHeight(80);
?>
PHP Arrays
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• An array stores multiple values in one single
variable:
Example:
<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and "
. $cars[2] . ".";
?>
PHP Arrays
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
Create an Array in PHP
• In PHP, the array() function is used to create an
array:
• array();
In PHP, there are three types of arrays:
• Indexed arrays - Arrays with a numeric index
• Associative arrays - Arrays with named keys
• Multidimensional arrays - Arrays containing one
or more arrays
PHP Indexed Arrays
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
There are two ways to create indexed arrays:
• The index can be assigned automatically
(index always starts at 0), like this:
• $cars = array("Volvo", "BMW", "Toyota");
or the index can be assigned manually:
$cars[0] = "Volvo";
$cars[1] = "BMW";
$cars[2] = "Toyota";
Get The Length of an Array - The
count() Function
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• The count() function is used to return the
length (the number of elements) of an array:
Example:
<?php
$cars = array("Volvo", "BMW", "Toyota");
echo count($cars);
?>
Loop Through an Indexed Array
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• To loop through and print all the values of an
indexed array, you could use a for loop, like this:
Example:
<?php
$cars = array("Volvo", "BMW", "Toyota");
$arrlength = count($cars);
for($x = 0; $x < $arrlength; $x++) {
echo $cars[$x];
echo "<br>";
}
?>
PHP Associative Arrays
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• Associative arrays are arrays that use named
keys that you assign to them.
• There are two ways to create an associative
array:
$age = array("Peter"=>"35", "Ben"=>"37",
"Joe"=>"43");
• or:
$age['Peter'] = "35";
$age['Ben'] = "37";
$age['Joe'] = "43";
PHP Associative Arrays
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
Example1
<?php
$age = array("Peter"=>"35", "Ben"=>"37",
"Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years old.";
?>
Example2
<?php
$age = array("Peter"=>"35", "Ben"=>"37",
"Joe"=>"43");
foreach($age as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
PHP - Sort Functions For Arrays
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
The following PHP array sort functions:
• sort() - sort arrays in ascending order
• rsort() - sort arrays in descending order
• asort() - sort associative arrays in ascending
order, according to the value
• ksort() - sort associative arrays in ascending
order, according to the key
• arsort() - sort associative arrays in descending
order, according to the value
• krsort() - sort associative arrays in descending
order, according to the key
PHP Global Variables - Superglobals
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• Several predefined variables in PHP are "superglobals",
which means that they are always accessible, regardless of
scope - and you can access them from any function, class or
file without having to do anything special.
The PHP superglobal variables are:
• $GLOBALS
• $_SERVER
• $_REQUEST
• $_POST
• $_GET
• $_FILES
• $_ENV
• $_COOKIE
• $_SESSION
PHP $_SERVER
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• $_SERVER is a PHP super global variable which holds
information about headers, paths, and script locations.
Example:
<?php
echo $_SERVER['PHP_SELF'];
echo "<br>";
echo $_SERVER['SERVER_NAME'];
echo "<br>";
echo $_SERVER['HTTP_HOST'];
echo "<br>";
echo $_SERVER['HTTP_REFERER'];
echo "<br>";
echo $_SERVER['HTTP_USER_AGENT'];
echo "<br>";
echo $_SERVER['SCRIPT_NAME'];
?>
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP $_REQUEST
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP $_REQUEST is used to collect data after submitting an HTML form.
Example:
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname">
<input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_REQUEST['fname'];
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}
}
?>
</body>
</html>
PHP $_POST
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
PHP $_POST is widely used to collect form data after submitting an HTML
form with method="post". $_POST is also widely used to pass variables.
Example:
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname">
<input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_POST['fname'];
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}
}
?>
</body>
</html>
PHP $_GET
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• PHP $_GET can also be used to collect form data
after submitting an HTML form with method="get".
• $_GET can also collect data sent in the URL.
• Assume we have an HTML page that contains a
hyperlink with parameters:
<html>
<body>
<a
href="test_get.php?subject=PHP&web=ycce.com">T
est $GET</a>
</body>
</html>
PHP $_GET
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• When a user clicks on the link "Test $GET", the
parameters "subject" and "web" is sent to
"test_get.php", and you can then access their values
in "test_get.php" with $_GET.
• The example below shows the code in
"test_get.php":
Example:
<html>
<body>
<?php
echo "Study " . $_GET['subject'] . " at " .
$_GET['web'];
?>
</body> </html>
PHP Date and Time
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
The PHP Date() Function
• The PHP date() function formats a timestamp to a
more readable date and time.
Syntax:
• date(format,timestamp)
Example:
<?php
echo "Today is " . date("Y/m/d") . "<br>";
echo "Today is " . date("Y.m.d") . "<br>";
echo "Today is " . date("Y-m-d") . "<br>";
echo "Today is " . date("l"); // l represents Day of week
?>
PHP Tip - Automatic Copyright Year
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• Use the date() function to automatically update the
copyright year on your website:
Example:
&copy; 2010-<?php echo date("Y")?>
• Get a Simple Time
Example
<?php
echo "The time is " . date("h:i:sa");
?>
PHP 5 Include Files
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
• It is possible to insert the content of one PHP file into
another PHP file (before the server executes it), with
the include or require statement.
Syntax:
include 'filename';
or
require 'filename';
PHP Exception Handling
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
<?php
//create function with an exception
function checkNum($number) {
if($number>1) {
throw new Exception("Value must be 1 or below");
}
return true;
}
//trigger exception in a "try" block
try {
checkNum(2);
//If the exception is thrown, this text will not be shown
echo 'If you see this, the number is 1 or below'; }
//catch exception
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
} ?>
TODAY TASK
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
Create One User Registration Form having fields
Name, Age, Address, Cell Number, College Name
, Designation etc.
And Print the above data on the same form at
the bottom of the form in Table Format.
BY
PRATIK TAMBEKAR
HEMANT HINGAVE
Ad

More Related Content

What's hot (20)

PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
Tiji Thomas
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
CPD INDIA
 
Php
PhpPhp
Php
Shyam Khant
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
Sehwan Noh
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
Geshan Manandhar
 
Css Ppt
Css PptCss Ppt
Css Ppt
Hema Prasanth
 
Lesson 2 php data types
Lesson 2   php data typesLesson 2   php data types
Lesson 2 php data types
MLG College of Learning, Inc
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
DivyanshGupta922023
 
Form Handling using PHP
Form Handling using PHPForm Handling using PHP
Form Handling using PHP
Nisa Soomro
 
Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
dharmendra kumar dhakar
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Taha Malampatti
 
jQuery
jQueryjQuery
jQuery
Dileep Mishra
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
PHP variables
PHP  variablesPHP  variables
PHP variables
Siddique Ibrahim
 
CSS
CSSCSS
CSS
People Strategists
 
What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
 
Php mysql
Php mysqlPhp mysql
Php mysql
Shehrevar Davierwala
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
Knoldus Inc.
 

Viewers also liked (20)

Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Jussi Pohjolainen
 
PHP
PHPPHP
PHP
sometech
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
Mohamed Loey
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
alexjones89
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
webhostingguy
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
Nisa Soomro
 
Linux.ppt
Linux.ppt Linux.ppt
Linux.ppt
onu9
 
Security and Performance - Italian WordPress Conference
Security and Performance - Italian WordPress ConferenceSecurity and Performance - Italian WordPress Conference
Security and Performance - Italian WordPress Conference
Maurizio Pelizzone
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
Guni Sonow
 
Php
PhpPhp
Php
rida mariam
 
String Manipulation in PHP
String Manipulation in PHPString Manipulation in PHP
String Manipulation in PHP
Suraj Motee
 
PHP HTML CSS Notes
PHP HTML CSS  NotesPHP HTML CSS  Notes
PHP HTML CSS Notes
Tushar Rajput
 
php tutorial - By Bally Chohan
php tutorial - By Bally Chohanphp tutorial - By Bally Chohan
php tutorial - By Bally Chohan
ballychohanuk
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14
Hassen Poreya
 
Even internet computers want to be free: Using Linux and open source software...
Even internet computers want to be free: Using Linux and open source software...Even internet computers want to be free: Using Linux and open source software...
Even internet computers want to be free: Using Linux and open source software...
North Bend Public Library
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
Bwsrang Basumatary
 
Font
FontFont
Font
Mohammad Bagher Adib Behrooz
 
Php variables (english)
Php variables (english)Php variables (english)
Php variables (english)
Mahmoud Masih Tehrani
 
Constructor and encapsulation in php
Constructor and encapsulation in phpConstructor and encapsulation in php
Constructor and encapsulation in php
SHIVANI SONI
 
Php File Operations
Php File OperationsPhp File Operations
Php File Operations
mussawir20
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
Mohamed Loey
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
alexjones89
 
Linux.ppt
Linux.ppt Linux.ppt
Linux.ppt
onu9
 
Security and Performance - Italian WordPress Conference
Security and Performance - Italian WordPress ConferenceSecurity and Performance - Italian WordPress Conference
Security and Performance - Italian WordPress Conference
Maurizio Pelizzone
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
Guni Sonow
 
String Manipulation in PHP
String Manipulation in PHPString Manipulation in PHP
String Manipulation in PHP
Suraj Motee
 
php tutorial - By Bally Chohan
php tutorial - By Bally Chohanphp tutorial - By Bally Chohan
php tutorial - By Bally Chohan
ballychohanuk
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14
Hassen Poreya
 
Even internet computers want to be free: Using Linux and open source software...
Even internet computers want to be free: Using Linux and open source software...Even internet computers want to be free: Using Linux and open source software...
Even internet computers want to be free: Using Linux and open source software...
North Bend Public Library
 
Constructor and encapsulation in php
Constructor and encapsulation in phpConstructor and encapsulation in php
Constructor and encapsulation in php
SHIVANI SONI
 
Php File Operations
Php File OperationsPhp File Operations
Php File Operations
mussawir20
 
Ad

Similar to Php Tutorial (20)

Lesson-5-php BY AAFREEN SHAIKH.pdf HSC INFORMATION TECHNOLOGY CHAP 5 PHP
Lesson-5-php BY AAFREEN SHAIKH.pdf HSC INFORMATION TECHNOLOGY CHAP 5 PHPLesson-5-php BY AAFREEN SHAIKH.pdf HSC INFORMATION TECHNOLOGY CHAP 5 PHP
Lesson-5-php BY AAFREEN SHAIKH.pdf HSC INFORMATION TECHNOLOGY CHAP 5 PHP
AAFREEN SHAIKH
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master
jeeva indra
 
Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
Robby Firmansyah
 
php Chapter 1.pptx
php Chapter 1.pptxphp Chapter 1.pptx
php Chapter 1.pptx
HambaAbebe2
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_master
PrinceGuru MS
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
AAFREEN SHAIKH
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
Arti Parab Academics
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
Alokin Software Pvt Ltd
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
KIRAN KUMAR SILIVERI
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
HASENSEID
 
PHP Basic & Variables
PHP Basic & VariablesPHP Basic & Variables
PHP Basic & Variables
M.Zalmai Rahmani
 
Php
PhpPhp
Php
Moorthy Haribabu
 
Php Basics
Php BasicsPhp Basics
Php Basics
Shaheed Udham Singh College of engg. n Tech.,Tangori,Mohali
 
Lecture 6: Introduction to PHP and Mysql .pptx
Lecture 6:  Introduction to PHP and Mysql .pptxLecture 6:  Introduction to PHP and Mysql .pptx
Lecture 6: Introduction to PHP and Mysql .pptx
AOmaAli
 
Introduction to php contains basic....pptx
Introduction to php contains basic....pptxIntroduction to php contains basic....pptx
Introduction to php contains basic....pptx
RanjithaGowda63
 
Php tutorialw3schools
Php tutorialw3schoolsPhp tutorialw3schools
Php tutorialw3schools
rasool noorpour
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 
Introduction to PHP_Slides by Lesley_Bonyo.pdf
Introduction to PHP_Slides by Lesley_Bonyo.pdfIntroduction to PHP_Slides by Lesley_Bonyo.pdf
Introduction to PHP_Slides by Lesley_Bonyo.pdf
MacSila
 
Lesson-5-php BY AAFREEN SHAIKH.pdf HSC INFORMATION TECHNOLOGY CHAP 5 PHP
Lesson-5-php BY AAFREEN SHAIKH.pdf HSC INFORMATION TECHNOLOGY CHAP 5 PHPLesson-5-php BY AAFREEN SHAIKH.pdf HSC INFORMATION TECHNOLOGY CHAP 5 PHP
Lesson-5-php BY AAFREEN SHAIKH.pdf HSC INFORMATION TECHNOLOGY CHAP 5 PHP
AAFREEN SHAIKH
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master
jeeva indra
 
php Chapter 1.pptx
php Chapter 1.pptxphp Chapter 1.pptx
php Chapter 1.pptx
HambaAbebe2
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_master
PrinceGuru MS
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
AAFREEN SHAIKH
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
Arti Parab Academics
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
HASENSEID
 
Lecture 6: Introduction to PHP and Mysql .pptx
Lecture 6:  Introduction to PHP and Mysql .pptxLecture 6:  Introduction to PHP and Mysql .pptx
Lecture 6: Introduction to PHP and Mysql .pptx
AOmaAli
 
Introduction to php contains basic....pptx
Introduction to php contains basic....pptxIntroduction to php contains basic....pptx
Introduction to php contains basic....pptx
RanjithaGowda63
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 
Introduction to PHP_Slides by Lesley_Bonyo.pdf
Introduction to PHP_Slides by Lesley_Bonyo.pdfIntroduction to PHP_Slides by Lesley_Bonyo.pdf
Introduction to PHP_Slides by Lesley_Bonyo.pdf
MacSila
 
Ad

Recently uploaded (20)

Machine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATIONMachine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATION
DarrinBright1
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
Guru Nanak Technical Institutions
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
PawachMetharattanara
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
Applications of Centroid in Structural Engineering
Applications of Centroid in Structural EngineeringApplications of Centroid in Structural Engineering
Applications of Centroid in Structural Engineering
suvrojyotihalder2006
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Journal of Soft Computing in Civil Engineering
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
Machine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATIONMachine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATION
DarrinBright1
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
PawachMetharattanara
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
Applications of Centroid in Structural Engineering
Applications of Centroid in Structural EngineeringApplications of Centroid in Structural Engineering
Applications of Centroid in Structural Engineering
suvrojyotihalder2006
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 

Php Tutorial

  • 2. BY PRATIK TAMBEKAR HEMANT HINGAVE PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP. PHP: Hypertext Preprocessor
  • 3. 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 BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 4. What is PHP? • PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) • PHP is compatible with almost all servers used today (Apache, IIS, etc.) • PHP supports a wide range of databases • PHP is free. Download it from the official PHP resource: www.php.net • PHP is easy to learn and runs efficiently on the server side BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 5. Basic PHP Syntax • A PHP script can be placed anywhere in the document. • A PHP script starts with <?php and ends with ?> • <!DOCTYPE html> <html> <body> <h1>PHP TUTORIAL</h1> <?php echo “YCCE NAGPUR”; ?> </body> </html> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 6. 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) BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 7. Basic PHP Syntax <!DOCTYPE html> <html> <body> <?php // This is a single-line comment # This is also a single-line comment /* This is a multiple-lines comment block that spans over multiple lines */ // You can also use comments to leave out parts of a code line $x = 5 /* + 15 */ + 5; echo $x; ?> </body> </html> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 8. PHP is a Loosely Typed Language • In the example above, notice that we did not have to tell PHP which data type the variable is. • PHP automatically converts the variable to the correct data type, depending on its value. • In other languages such as C, C++, and Java, the programmer must declare the name and type of the variable before using it. BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 9. 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 BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 10. PHP The global Keyword • The global keyword is used to access a global variable from within a function. • To do this, use the global keyword before the variables <?php $x = 5; $y = 10; function myTest() { global $x, $y; $y = $x + $y; } myTest(); echo $y; ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 11. PHP The static Keyword • <?php function myTest() { static $x = 0; echo $x; $x++; } myTest(); myTest(); myTest(); ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 12. The PHP echo Statement <?php echo "<h2>PHP is Fun!</h2>"; echo "Hello world!<br>"; echo "I'm about to learn PHP!<br>"; echo "This ", "string ", "was ", "made ", "with multiple parameters."; ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 13. The PHP print Statement <?php $txt1 = "Learn PHP"; $txt2 = “ycce.com"; $x = 5; $y = 4; print "<h2>$txt1</h2>"; print "Study PHP at $txt2<br>"; print $x + $y; ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 14. PHP Data Types • PHP supports the following data types: • String • Integer • Float (floating point numbers - also called double) • Boolean • Array • Object • NULL • Resource BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 15. PHP Data Types 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 = 5985; var_dump($x); ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 16. PHP Data Types PHP Array: <?php $cars = array("Volvo","BMW","Toyota"); var_dump($cars); ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 17. PHP Object • An object is a data type which stores data and information on how to process that data. • In PHP, an object must be explicitly declared. <?php class Car { function Car() { $this->model = "VW"; } } // create an object $herbie = new Car(); // show object properties echo $herbie->model; ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 18. 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. • Note: If a variable is created without a value, it is automatically assigned a value of NULL. Example <?php $x = "Hello world!"; $x = null; var_dump($x); ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 19. PHP String Functions Get The Length of a String: • The PHP strlen() function returns the length of a string (number of characters). • The example below returns the length of the string "Hello world!": Example <?php echo strlen("Hello world!"); // outputs 12 ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 20. PHP String Functions Count The Number of Words in a String: Example <?php echo str_word_count("Hello world!"); // outputs 2 ?> Reverse a String: Example <?php echo strrev("Hello world!"); ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 21. PHP String Functions Search For a Specific Text Within a String: • If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE. Example <?php echo strpos("Hello world!", "world"); // outputs 6 ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 22. PHP String Functions • Replace Text Within a String: Example <?php echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly! ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 23. 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). • Note: Unlike variables, constants are automatically global across the entire script. BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 24. PHP Constants Syntax: define(name, value, case-insensitive) Parameters: • name: Specifies the name of the constant • value: Specifies the value of the constant • case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 25. PHP Constants <?php define(“YASHWANTRAO", "Welcome to YCCE!"); echo YASHWANTRAO; ?> Constants are Global: <?php define(" YASHWANTRAO ", " Welcome to YCCE!"); function myTest() { echo YASHWANTRAO; } myTest(); ?> BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 26. 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 BY PRATIK TAMBEKAR HEMANT HINGAVE
  • 27. PHP Operators BY PRATIK TAMBEKAR HEMANT HINGAVE PHP Arithmetic Operators:
  • 28. PHP Operators BY PRATIK TAMBEKAR HEMANT HINGAVE PHP Assignment Operators:
  • 29. PHP Operators BY PRATIK TAMBEKAR HEMANT HINGAVE PHP Comparison Operators:
  • 30. PHP Operators BY PRATIK TAMBEKAR HEMANT HINGAVE PHP Increment / Decrement Operators:
  • 31. PHP Operators BY PRATIK TAMBEKAR HEMANT HINGAVE PHP Logical Operators:
  • 32. PHP Operators BY PRATIK TAMBEKAR HEMANT HINGAVE PHP String Operators:
  • 33. PHP Operators BY PRATIK TAMBEKAR HEMANT HINGAVE PHP Array Operators:
  • 34. PHP Conditional Statements BY PRATIK TAMBEKAR HEMANT HINGAVE • In PHP we have the following conditional statements: • if statement - executes some code only if a specified condition is true • if...else statement - executes some code if a condition is true and another code if the condition is false • if...elseif....else statement - specifies a new condition to test, if the first condition is false • switch statement - selects one of many blocks of code to be executed
  • 35. PHP - The if Statement BY PRATIK TAMBEKAR HEMANT HINGAVE • The if statement is used to execute some code only if a specified condition is true. Syntax if (condition) { code to be executed if condition is true; }
  • 36. PHP - The if...else Statement BY PRATIK TAMBEKAR HEMANT HINGAVE • Use the if....else statement to execute some code if a condition is true and another code if the condition is false. Syntax: if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; }
  • 37. PHP - The if...elseif....else Statement BY PRATIK TAMBEKAR HEMANT HINGAVE • Use the if....elseif...else statement to specify a new condition to test, if the first condition is false. Syntax: if (condition) { code to be executed if condition is true; } elseif (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; }
  • 38. PHP - The switch Statement BY PRATIK TAMBEKAR HEMANT HINGAVE • Use the switch statement to select one of many blocks of code to be executed. Syntax: switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; case label3: code to be executed if n=label3; break; ... default: code to be executed if n is different from all labels; }
  • 39. PHP Loops BY PRATIK TAMBEKAR HEMANT HINGAVE In PHP, we have the following looping statements: • while - loops through a block of code as long as the specified condition is true • do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true • for - loops through a block of code a specified number of times • foreach - loops through a block of code for each element in an array
  • 40. while Loop BY PRATIK TAMBEKAR HEMANT HINGAVE • The while loop executes a block of code as long as the specified condition is true. Syntax: while (condition is true) { code to be executed; }
  • 41. do...while Loop BY PRATIK TAMBEKAR HEMANT HINGAVE • The do...while loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true. Syntax: do { code to be executed; } while (condition is true);
  • 42. for Loop BY PRATIK TAMBEKAR HEMANT HINGAVE • The for loop is used when you know in advance how many times the script should run. Syntax: for (init counter; test counter; increment counter) { code to be executed; }
  • 43. foreach Loop BY PRATIK TAMBEKAR HEMANT HINGAVE • The foreach loop works only on arrays, and is used to loop through each key/value pair in an array. Syntax: foreach ($array as $value) { code to be executed; }
  • 44. foreach Loop BY PRATIK TAMBEKAR HEMANT HINGAVE • For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element. Example: <?php $colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>"; } ?>
  • 45. PHP Functions BY PRATIK TAMBEKAR HEMANT HINGAVE PHP User Defined Functions • Besides the built-in PHP functions, we can create our own functions. • A function is a block of statements that can be used repeatedly in a program. • A function will not execute immediately when a page loads. • A function will be executed by a call to the function.
  • 46. Create a User Defined Function in PHP BY PRATIK TAMBEKAR HEMANT HINGAVE • A user defined function declaration starts with the word "function": Syntax: function functionName() { code to be executed; } • Note: A function name can start with a letter or underscore (not a number).
  • 47. Create a User Defined Function in PHP BY PRATIK TAMBEKAR HEMANT HINGAVE Example: <?php function setHeight($minheight = 50) { echo "The height is : $minheight <br>"; } setHeight(350); setHeight(); // will use the default value of 50 setHeight(135); setHeight(80); ?>
  • 48. PHP Arrays BY PRATIK TAMBEKAR HEMANT HINGAVE • An array stores multiple values in one single variable: Example: <?php $cars = array("Volvo", "BMW", "Toyota"); echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "."; ?>
  • 49. PHP Arrays BY PRATIK TAMBEKAR HEMANT HINGAVE Create an Array in PHP • In PHP, the array() function is used to create an array: • array(); In PHP, there are three types of arrays: • Indexed arrays - Arrays with a numeric index • Associative arrays - Arrays with named keys • Multidimensional arrays - Arrays containing one or more arrays
  • 50. PHP Indexed Arrays BY PRATIK TAMBEKAR HEMANT HINGAVE There are two ways to create indexed arrays: • The index can be assigned automatically (index always starts at 0), like this: • $cars = array("Volvo", "BMW", "Toyota"); or the index can be assigned manually: $cars[0] = "Volvo"; $cars[1] = "BMW"; $cars[2] = "Toyota";
  • 51. Get The Length of an Array - The count() Function BY PRATIK TAMBEKAR HEMANT HINGAVE • The count() function is used to return the length (the number of elements) of an array: Example: <?php $cars = array("Volvo", "BMW", "Toyota"); echo count($cars); ?>
  • 52. Loop Through an Indexed Array BY PRATIK TAMBEKAR HEMANT HINGAVE • To loop through and print all the values of an indexed array, you could use a for loop, like this: Example: <?php $cars = array("Volvo", "BMW", "Toyota"); $arrlength = count($cars); for($x = 0; $x < $arrlength; $x++) { echo $cars[$x]; echo "<br>"; } ?>
  • 53. PHP Associative Arrays BY PRATIK TAMBEKAR HEMANT HINGAVE • Associative arrays are arrays that use named keys that you assign to them. • There are two ways to create an associative array: $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); • or: $age['Peter'] = "35"; $age['Ben'] = "37"; $age['Joe'] = "43";
  • 54. PHP Associative Arrays BY PRATIK TAMBEKAR HEMANT HINGAVE Example1 <?php $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); echo "Peter is " . $age['Peter'] . " years old."; ?> Example2 <?php $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); foreach($age as $x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>"; } ?>
  • 55. PHP - Sort Functions For Arrays BY PRATIK TAMBEKAR HEMANT HINGAVE The following PHP array sort functions: • sort() - sort arrays in ascending order • rsort() - sort arrays in descending order • asort() - sort associative arrays in ascending order, according to the value • ksort() - sort associative arrays in ascending order, according to the key • arsort() - sort associative arrays in descending order, according to the value • krsort() - sort associative arrays in descending order, according to the key
  • 56. PHP Global Variables - Superglobals BY PRATIK TAMBEKAR HEMANT HINGAVE • Several predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special. The PHP superglobal variables are: • $GLOBALS • $_SERVER • $_REQUEST • $_POST • $_GET • $_FILES • $_ENV • $_COOKIE • $_SESSION
  • 57. PHP $_SERVER BY PRATIK TAMBEKAR HEMANT HINGAVE • $_SERVER is a PHP super global variable which holds information about headers, paths, and script locations. Example: <?php echo $_SERVER['PHP_SELF']; echo "<br>"; echo $_SERVER['SERVER_NAME']; echo "<br>"; echo $_SERVER['HTTP_HOST']; echo "<br>"; echo $_SERVER['HTTP_REFERER']; echo "<br>"; echo $_SERVER['HTTP_USER_AGENT']; echo "<br>"; echo $_SERVER['SCRIPT_NAME']; ?>
  • 61. PHP $_REQUEST BY PRATIK TAMBEKAR HEMANT HINGAVE PHP $_REQUEST is used to collect data after submitting an HTML form. Example: <html> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> Name: <input type="text" name="fname"> <input type="submit"> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // collect value of input field $name = $_REQUEST['fname']; if (empty($name)) { echo "Name is empty"; } else { echo $name; } } ?> </body> </html>
  • 62. PHP $_POST BY PRATIK TAMBEKAR HEMANT HINGAVE PHP $_POST is widely used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables. Example: <html> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> Name: <input type="text" name="fname"> <input type="submit"> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // collect value of input field $name = $_POST['fname']; if (empty($name)) { echo "Name is empty"; } else { echo $name; } } ?> </body> </html>
  • 63. PHP $_GET BY PRATIK TAMBEKAR HEMANT HINGAVE • PHP $_GET can also be used to collect form data after submitting an HTML form with method="get". • $_GET can also collect data sent in the URL. • Assume we have an HTML page that contains a hyperlink with parameters: <html> <body> <a href="test_get.php?subject=PHP&web=ycce.com">T est $GET</a> </body> </html>
  • 64. PHP $_GET BY PRATIK TAMBEKAR HEMANT HINGAVE • When a user clicks on the link "Test $GET", the parameters "subject" and "web" is sent to "test_get.php", and you can then access their values in "test_get.php" with $_GET. • The example below shows the code in "test_get.php": Example: <html> <body> <?php echo "Study " . $_GET['subject'] . " at " . $_GET['web']; ?> </body> </html>
  • 65. PHP Date and Time BY PRATIK TAMBEKAR HEMANT HINGAVE The PHP Date() Function • The PHP date() function formats a timestamp to a more readable date and time. Syntax: • date(format,timestamp) Example: <?php echo "Today is " . date("Y/m/d") . "<br>"; echo "Today is " . date("Y.m.d") . "<br>"; echo "Today is " . date("Y-m-d") . "<br>"; echo "Today is " . date("l"); // l represents Day of week ?>
  • 66. PHP Tip - Automatic Copyright Year BY PRATIK TAMBEKAR HEMANT HINGAVE • Use the date() function to automatically update the copyright year on your website: Example: &copy; 2010-<?php echo date("Y")?> • Get a Simple Time Example <?php echo "The time is " . date("h:i:sa"); ?>
  • 67. PHP 5 Include Files BY PRATIK TAMBEKAR HEMANT HINGAVE • It is possible to insert the content of one PHP file into another PHP file (before the server executes it), with the include or require statement. Syntax: include 'filename'; or require 'filename';
  • 68. PHP Exception Handling BY PRATIK TAMBEKAR HEMANT HINGAVE <?php //create function with an exception function checkNum($number) { if($number>1) { throw new Exception("Value must be 1 or below"); } return true; } //trigger exception in a "try" block try { checkNum(2); //If the exception is thrown, this text will not be shown echo 'If you see this, the number is 1 or below'; } //catch exception catch(Exception $e) { echo 'Message: ' .$e->getMessage(); } ?>
  • 69. TODAY TASK BY PRATIK TAMBEKAR HEMANT HINGAVE Create One User Registration Form having fields Name, Age, Address, Cell Number, College Name , Designation etc. And Print the above data on the same form at the bottom of the form in Table Format.
  翻译: