Presentation is loading. Please wait.

Presentation is loading. Please wait.

Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics.

Similar presentations


Presentation on theme: "Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics."— Presentation transcript:

1 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics

2 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] What is it? PHP is a scripting language commonly used on web servers. –Stands for “PHP: Hypertext Preprocessor” –Open source –Embedded code –Comparable with ASP –Multiple operating systems/web servers

3 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] The PHP Resource

4 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] What can it do? Dynamic generation of web-page content Database interaction Processing of user supplied data File handling Text processing Network interaction And more…

5 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Fundamentals PHP is embedded within xhtml pages within the tags: The short version of these tags can also be used: Each line of PHP is terminated, like MySQL, with a semi-colon.

6 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Hello World! PHP Test Hello World! ’; ?>

7 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Let’s get started then.. PHP is enabled on the Birkbeck server Create your pages in your personal space Access them via –http://students.dcs.bbk.ac.uk/userid/web/ –This points to your I:\web\ directory REMEMBER –.php extension so server knows to parse it! –Use full web address not local path Otherwise server will not parse the file

8 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] HOE 1 : Preparing to code with PHP

9 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Literals.. All strings must be enclosed in single of double quotes: ‘Hello’ or “Hello”. Numbers are not in enclosed in quotes: 1 or 45 or Booleans (true/false) can be written directly as true or false.

10 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Comments // This is a comment # This is also a comment /* This is a comment that is spread over multiple lines */ Do not nest multi-line comments // recommended over #

11 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Comments

12 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Displaying Data There are two language constructs available to display data: print() and echo(). They can be used with or without brackets. Note that the data ‘displayed’ by PHP is actually parsed by your browser as HTML. View source to see actual output.

13 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Displaying data

14 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Escaping Characters Some characters are considered ‘special’ Escape these with a backslash \ Special characters will be flagged when they arise, for example a double or single quote belong in this group…

15 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Escaping Characters

16 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Variables: What are they? When we work in PHP, we often need a labelled place to store a value (be it a string, number, whatever) so we can use it in multiple places in our script. These labelled ‘places’ are called VARIABLES

17 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Variables: Naming $ followed by variable name Case sensitive –$variable differs from $Variable –Stick to lower-case to be sure! Name must started with a letter or an underscore –Followed by any number of letters, numbers and underscores

18 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Variables: example

19 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Constants Constants (unchangeable variables) can also be defined. Each constant is given a name (note no preceding dollar is applied here). By convention, constant names are usually in UPPERCASE.

20 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Constants

21 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] “ or ‘ ? There is a difference between strings written in single and double quotes. In a double-quoted string any variable names are expanded to their values. In a single-quoted string, no variable expansion takes place.

22 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] “ or ‘ ?

23 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] “ or ‘ ?

24 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] HOE 2 : The Fundamentals

25 Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] Review We’ve started PHP.. –Escaping XHTML –Comments –Basic Syntax –Variables –Constants


Download ppt "Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics."

Similar presentations


Ads by Google