Transcript Document

IT – som værktøj

Oktober 2002 Bent Thomsen Institut for Datalogi Aalborg Universitet Bent Thomsen - FIT 1-1 1

Introduction to PHP

Bent Thomsen

What is PHP?

• PHP is a generalized Open Source

Server Side Scripting

Language that generates HTML content • PHP: Recursive Acronym for – PHP: Hypertext Preprocessor • PHP was created by Rasmus Lerdorf in 1994 as a tool for Web Development • PHP is simple for beginners, yet a powerful tool for the professional Web Developer

Embedding PHP in HTML is different from writing a script in other languages like Perl, but similar to JavaScript Instead of writing a program with lots of commands to output HTML, you write an HTML script with some embedded code to do something (in the example on the next page, to output some text). The PHP code is enclosed in start and end tags that allow you to jump into and out of "PHP mode". An example follows

Embedding PHP in HTML

Example

HTML Embedding

– SGML Style:

echo “Hello World!”; ?> – XML Style:

echo “Hello World!”; ?> – ASP Style: <%= “Hello World!”; %> – JavaScript Style:

PHP vs. JavaScript

• What distinguishes PHP from client-side JavaScript?

• PHP code is executed on the server. • If you were to have a script similar to the above on your server, the client would receive the results of running that script, with no way to determine what the underlying code may be.

Client-side execution using JavaScript

JavaScript

Web-Client Web-Browser WWW Web-Server

HTML Page ...