Vous êtes sur la page 1sur 5

Introduction to PHP

Julie Scott
OIT, Faculty Support
Program Lead, Learning Technology

What is PHP?
• PHP = Hypertext Preprocessor
• Why not HP or HPP?
• PHP is a recursive acronym.
• An acronym in which the first letter of the
first word represented by the acronym is
the acronym itself.
• For example: GNU “GNU is Not UNIX!”

More….What is PHP?
• An open source, server-side, HTML
embedded scripting language.
• It is used to create dynamic Web pages.
• PHP script is enclosed within special PHP
tags.
• This allows you to jump between HTML
and PHP.

1
More….What is PHP?
• PHP is executed on the server.
• The client cannot view the PHP code.
• PHP can perform any task that any CGI
program can do.
• Its strength lies in its compatibility with
many types of databases.
• Also, PHP can talk across networks using
IMAP, SNMP, NNTP, POP3, or HTTP

PHP versus Perl


• Shorter development time.
• Easy-to-use scripting language.
• PHP code is significantly easier to
maintain and update than comparable Perl
or ASP code.
• Cross-platform compatibility – will work on
any of the existing Internet servers.

Learning PHP
• Some Books

Publisher Book Title

O’Reilly Programming PHP


PHP Cookbook
Wrok PHP Programming

SAMS PHP Developers


Handbook

2
Learning PHP

• Online Tutorials
• Zend http://www.zend.com/zend/tut/
• PHP.net
• Dev Shed:
http://www.devshed.com/c/b/PHP/
• PHP and Postgres
http://pgsql.designmagick.com/

PHP Editors
• Dreamweaver MX in code view
• Homesite

Free editors
• PHP Edit (Windows)
• BBEdit Lite (Macintosh)

For a comparison of editors see


• http://www.php-editors.com

Basic PHP syntax


PHP TAGS: <?php ?>
PHP statements end in a semicolon ;

// this is an inline comment

###################
# another comment #
###################

/* this is another type of multi-line


comment */

3
More….Basic PHP
• Variable names begin with a “$” sign and
are case sensitive
• Function names are NOT case sensitive
• Class names are NOT case sensitive
• Data can be stored in arrays
• Arrays are associative or indexed
• Arrays can have more than one data type

More….Basic PHP
• Variables can be local or global
– Global variables can be used anywhere
– Local variables are local to a function or class
• Most variables are treated as strings
• Special variables exist
– Server variables
– Form variables
– Session variables

WMU Specifics
• wwwtest.wmich.edu
• For SQL database access contact Derek
– We support PostgreSQL
– Note most online tutorials use mySQL
• You can read and write flat files
– Files must be protected so the server can
read and write to them

4
Some Examples
• Reading and Writing Flat Files
– http://www.wmich.edu/~scott/
– (click on the PHP-Workshop Link)
– http://www.wmich.edu/itc/workshops
• Check WebCT workshop registeration

• Reading SQL database


– http://www.wmich.edu/itc/workshops/
• Old workshops not displayed
• New workshops displayed on separate link

What is a Dynamic Web Page


A dynamic Web page is a
page that interacts with the
user, so that each user visiting
the page sees customized
information
[back]

Exercise One

<body>
<?php
$today = "Wednesday" ;
echo " <h2>Hello World</h2>";
echo " Today is $today";
echo phpinfo();
?>
</body>

Vous aimerez peut-être aussi