1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

16
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

Transcript of 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

Page 1: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

1

CS428 Web EngineeringLecture 18

Introduction (PHP - I)

Page 2: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

• PHP is a server side scripting language.

• Through PHP we can develop dynamic websites.

• Static Websites: those websites which structure contents are not changing. User’s can’t bring changing to the contents.

• Dynamic Websites: those websites, whose structure and contents are changing e.g. facebook.com (user upload pictures, links, videos, comments) User is interacting with the website and change the contents or modify the contents.

What is PHP?

Page 3: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

• JavaScript is another example of popular scripting language.

• Unlike JavaScript, PHP run on server machine, JavaScript run on client machine.

• Client side = User’s Browser• Server side = Web Server

• Because PHP run on server, so we need a web server to run it on.

Page 4: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

• PHP is designed for use with HTML.– PHP can be embedded with HTML.– PHP return HTML to browser.– PHP code is our input.– Web pages is out output.

• PHP provides more flexibility than HTML alone because through HTML you can create only static web pages, through PHP you create dynamic web pages.

• PHP syntax is similar to C, Java and Perl.• If you have knowledge of ASP then it will helpful to

learn PHP. We can say ASP is Microsoft version of PHP.

Page 5: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

Why use PHP?• You want to know the limits of HTML, and you want

to do more.• PHP is Open Source/Free Software.

(open source means, source code is available for every one for study, use and modify)

(free software means its free of cost to download and free to use)

• PHP is cross platform to develop, to deploy and to use. (means we put PHP on window server, on MAC server or on Linux/Unix server.)

• PHP is web development specific.• PHP can be object oriented, especially version 5.

Page 6: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

INSTALLATION• You will need?

Web Server PHP Database Text Editor Web Browser

Page 7: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

Windows InstallationAll-in-one Packages

• WAMP:www.wampserver.com/en/index.php

• XAMPP:www.apachefriends.org/

Page 8: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

Embedding PHP• PHP is embedded in html.

• <?php ?>, tells web server begin and ends the php commands.

• The server access the webpage, it knows to be ready for php because we have .php extension.

• Server still needs some extension where php start and stops, with <?php it turned on php, start filtering

Page 9: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

VARIATION on PHPShort open tags

(considered bad form)

<? ?>

<?= ?>

Page 10: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

NOTE• We will embed php code in html code.

• Whenever we embed php code in html, the file extension will always be .php, otherwise if extension will .html. The server treats it the php code as text.

• PHP code will embed in anywhere of HTML code.

Page 11: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

STRUCTURE OF BASIC PHP STATEMENT• <?php echo “Hello World!”; ?>

• <?php print “Hello World!”; ?>

Instruction separator, this is end of this instruction

echo is a function, which print something

Page 12: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

CONCATENATION • <?php echo “Hello” . “ World!”; ?>

• <?php echo 2+3; ?>

Dot (.) is used to concatenate two strings

Page 13: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

13

Case Sensitivity in PHP• Programming language constructs in PHP are

mostly case insensitive.

<?php

echo "<p>Explore <strong>Africa</strong>, <br />";

Echo "<strong>South America</strong>, <br />";

ECHO " and <strong>Australia</strong>!</p>";

?>

Page 14: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

The Operational Trail• What happens, when you actually ask for a

URL in your browser before you get HTML back to you.

Browser hp

Server

Find Page Hello.php

Return HTML

Process PHP

Databases

Apache

Page 15: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

COMMENTS IN PHP• Single line comments

// single line comments are like this

# or like this

• Double line comments

/* our double line comment here

and we can keep typing

and typing

*/

Page 16: 1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)

Difference b/w Desktop and Web App• Desktop software or app execute only at

local system, its extension is .exe

• Online web apps run when a request reach to server, that request indicate a file on server that web server execute this file and send result back to client’s browser.