You are on page 1of 17

Php

New Chapter
Intro..
Php

● PHP is an acronym for "Hypertext Preprocessor.”

● It was originally created by Danish-Canadian programmer Rasmus


Lerdorf in 1993 and released in 1995.

● It is an open source, widely used language for web development.

● It is a server scripting language, which means php scripts are executed on


the server.

● It has been used to build many CMS (Content Management System) like
WordPress, Drupal, Shopify, WooCommerce etc.
Features

● Open-source
● Easy to use ( C-like and Perl-like syntax)
● Stable and fast
● Multiplatform Support
● Supports various databases
● Many common built-in libraries
Conti…

● Cost efficient
● Platform independent
● It is an interpreted language
● Help from community
Who uses php ?

● Facebook
● Wikipedia
● Tumblr
● Slack
● MailChimp
● Etsy
● WordPress
How page request works :

1. Client from browser send HTTP request (with POST/GET variables).


2. Apache recognizes that a PHP script is requested and sends the request
to PHP module.
3. PHP interpreter executes PHP script, collects script output and sends it
back.
4. Apache replies to client using the PHP script output as HTML output.
First program

● Start xampp/wamp app


● Start server
● Open new file in any editor
● Write the program similar to the one in next slide
● Save your program with extension .php
Basic Example

<!DOCTYPE html>
<html>
<head>
<title>PHP!</title>
</head>
<body>
<p>
<?php echo "Hello world!"; ?>
</p>
</body>
</html>
Or you can…

<?php
header("Content-Type: text/plain");
echo "Hello World";
?>
Some uses

● PHP can handle forms, i.e. gather data from files, save data to a file, thru
email
● you can send data, return data to the user.
● You add, delete, modify elements within your database thru PHP.
Variables

● No declaration required.
● A new variable is created & gets stored when we assign a value to it.
● eg $text = “Hello World”;
● The above statement will create a new variable and assign the string
value ‘hello world’ to it, at the same time.
● echo ‘this is $text’;
● echo ‘this is’.$text.’only’;
● Both the above statements work the same.
Accessing input tags

<form method="get">
<input type=“text” name=“user”>
</form>

<?php
echo $_GET[“user"];
?>
Program Flow Control

If(condition)
{
logic;
}
Program Flow Control

● If
● If-else
● If-elseif
● If-elseif-else
● switch
● for loop
● foreach loop
● while loop
● do-while loop
● break
● continue
Example

● Create calc

You might also like