You are on page 1of 21

What is PHP?

Earlier it was Personal Home Page


PHP == ‘Hypertext Pre-processor’
Open-source, server-side scripting language
Used to generate dynamic web-pages
It was created in 1994 by Rasmus Lerdorf.
Various built-in functions allow for fast
development
Compatible with many popular databases
Why PHP?
Easy to learn
Best suited for rapid application devp.
Easy to implement
Run on most every platform.
It is free
Website and Web page
A website is a business way to
communicate
A web page is a plain text document with
formatting instruction of HTML, which is
interpreted by web browser.
Web pages transferred and accessed by
HTTP.
Web server
Web server can be refer as a computer
hardware or software application that can
be helps to deliver the content that can be
accessed through the Internet.
Use of Web Server is to host website,
data storage and enterprise applications.
World Wide Web
In 1994 Tim Berners- Lee decided to
constitute the www.
To regulate and development of
technologies i.e HTML, HTTP.
Where PHP can used
PHP is used in combination of various
code web application systems, web
frameworks.
We can made E-commerce, web
management software and so on..
Best Live example is PHP.
What is required
1. Laptop/Computer
2. Text Editor(Notepad++,Dreamweaver,
Sublime).
3.Wamp or Xampp Server
4. Web Browser (Crome or Firefox)
What does PHP code look like?
Structurallysimilar to C/C++
Supports procedural and object-oriented paradigm
(to some degree)
All PHP statements end with a semi-colon
Each PHP script must be enclosed in the reserved
PHP tag

<?php

?>
Comments in PHP
Standard C, C++, and shell comment symbols

// C++ and Java-style comment

# Shell-style comments

/* C-style comments
These can span multiple lines */
Variables in PHP
PHP variables must begin with a “$” sign
Global and locally-scoped variables
◦ Global variables can be used anywhere
◦ Local variables restricted to a function
or class
Certain variable names reserved by PHP
◦ Form variables ($_POST, $_GET)
◦ Server variables ($_SERVER)
◦ Etc.
Variable usage & echo
<?php
$Fee = 25; // Numerical variable
$Text = “Hello”; // String variable

$Fee= ($foo * 7); // Multiplies foo by 7


$Text = ($Text * 7); // Invalid
expression
?>

The PHP command ‘echo’ is used to output


the parameters passed to it
◦ The typical usage for this is to send data to
the client’s web-browser
PHP Control Structures
 Control Structures: Are the structures within a language that all
us to control the flow of execution through a program or script.
 Grouped into conditional (branching) structures (e.g. if/else)
and repetition structures (e.g. while loops).
 Example if/else if/else statement:

if ($res == 0) {
echo ‘The variable res is equal to 0’;
}
else if (($res > 0) && ($res <= 5)) {
echo ‘The variable res is between 1 and 5’;
}
else {
echo ‘The variable res is equal to’.$res;
}
If ... Else...
 If (condition)
{ <?php
If($user==“John”)
Statements;
{
echo “Hello John.”;
}
}
Else Else
{
{ echo “You are not John.”;
}
Statement;
?>
}
While Loops
While (condition)
<?php
$count=0;
{ While($count<3)
{
Statements; Print “hello PHP. ”;
$count += 1;
} // $count = $count + 1;
// or
// $count++;
?>

hello PHP. hello PHP. hello PHP.


PHP - Forms
•Access to the HTTP POST and GET data is
simple in PHP
•The global variables $_POST[] and $_GET[]
contain the request data
<?php
if ($_POST["submit"])
echo "<h2>You clicked Submit!</h2>";
else if ($_POST["cancel"])
echo "<h2>You clicked Cancel!</h2>";
?>
<form action="form.php" method="post">
<input type="submit" name="submit" value="Submit">
<input type="submit" name="cancel" value="Cancel">
</form>
First PHP script
 Save as sample.php:
<!– sample.php -->
<html><body>
<strong>Hello World!</strong><br />
<?php
echo “<h2>Hello, World</h2>”;
?>
<?php
$myvar = "Hello World";
echo $myvar;
?>
</body></html>
Create your own homepage

Login page
Registration Page
Validation Page
Admin Page
Home Page
Static Website
Static Website
Advantages
Easy to development
Cheap to development
Cheap to host
Disadvantages
Require web development expertise to
update site.
Changes and updates are very consuming
Site not as useful for the user
Dynamic Website
A site whose construction is controlled by
an application server processed by server-
side scripts.
◦ Pages of the website are not coded saved
separately.
◦ The design/template (look and feel) is saved
separately.

You might also like