web programming with php (1)

18
Web Programming with PHP (1)

Upload: afra

Post on 06-Jan-2016

22 views

Category:

Documents


1 download

DESCRIPTION

Web Programming with PHP (1). Pre-amble (1) What is programming?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Web Programming with PHP (1)

Web Programming with PHP (1)

Page 2: Web Programming with PHP (1)

- Computer programming (often shortened to programming or coding) is the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language. The code may be a modification of an existing source or something completely new. The purpose of programming is to create a program that exhibits a certain desired behaviour (customization). The process of writing source code often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic. (Wikipedia)

- Structured programming can be seen as a subset or sub-discipline of procedural programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO statement.

- At a low level, structured programs are often composed of simple, hierarchical program flow structures. These are sequence, selection, and repetition (iteration)

Pre-amble (1) What is programming?

Page 3: Web Programming with PHP (1)

- an example of a structuring technique or methodology is Jackson Structured Programming (JSP) developed in the 1970’s by Michael Jackson

- based on correspondences between data stream structure and program structure, JSP structures programs and data in terms of sequences, iterations and selections

- an example of a JSP diagram:

Pre-amble (2) Jackson Structured Programming

Page 4: Web Programming with PHP (1)

Pre-amble (3) Programming paradigms

- a programming paradigm is a fundamental style of computer programming. (Compare with a methodology, which is a style of solving specific software engineering problems). Paradigms differ in the concepts and abstractions used to represent the elements of a program (such as objects, functions, variables, constraints, etc.) and the steps that compose a computation (assignation, evaluation, continuations, data flows, etc.).

- paradigms include - procedural programming, functional programming, object-oriented programming, event-driven programming, process-oriented programming, logic-oriented programming etc.

- some languages (e.g. ruby, xslt) are oriented towards certain paradigms (oo, functional) and some languages (php) can support multiple paradigms (procedural, oo, functional) though it is usually thought of as a procedural language.

Page 5: Web Programming with PHP (1)

Pre-amble (4) Remembering the Web (1)

1993

Page 6: Web Programming with PHP (1)

Pre-amble (5) Remembering the Web (2)

Basic web 1.0 architecture & communication

Page 7: Web Programming with PHP (1)

Pre-amble (6) stuff you (already) need to know

basic htmlrecognize and write basic xhtml- the common tags?- common form layout and data-types?- well-formed?- doctype declaration?

basic cssrecognize and write basic css- basic css syntax?- the notions of external/embedded/inline styles? - the basic idea behind the document object model (dom)?

basic javascriptrecognize basic javascript syntax?- know in what situations and tasks javascript is a useful technology?

Basic html, css & javascript

Page 8: Web Programming with PHP (1)

PHP OriginsOriginally created by Rasmus Lerdorf (born Greenland, educated in

Canada) around 1995

PHP originally abbreviated as ‘Personal Home Pages’, now known as ‘PHP Hypertext Preprocessor’

Other key developers: Zeev Surashi and Andi Gutmans (Israel) responsible for PHP 3.0 - a complete re-write of the original PHP/F1 engine (1997)

PHP is Open Source softwareFirst version PHP/FI released 1995PHP 5.0 released July 2004Current version is 5.3.0PHP version 5.2.4 current at UWE PHP Version 6 due for release late 2009 / early 2010

Page 9: Web Programming with PHP (1)

Scripting languages

• A scripting language is:– often evolved not designed– cross-platform since interpreter is easy to port– designed to support a specific task – PHP Web support– un-typed variables (but values are typed) – implicit variable declaration – implicit type conversion – stored only as script files– compiled on demand– may run on the server (PHP, Perl) or the client (Javascript)

• What are the potential differences in programming using an interpreted scripting language like PHP in place of a compiled language (e.g. Java in JSP, .NET)?

Page 10: Web Programming with PHP (1)

PHP details

• Procedural language– Compare with Javascript which is event-driven

• C-like syntax - { } ;• Extensive Function Library• Good Web-server integration

– Script embedded in HTML– Easy access to form data and output of HTML pages

• Not fully (compulsorily) object-oriented – Java is fully object oriented – all functions have to be

in a class– In PHP, classes are additional but quite simple to use

Page 11: Web Programming with PHP (1)

PHP and HTML

• HTML-embedded– PHP scripts are essentially HTML pages with

the occasional section of PHP script.

– PHP script is enclosed in the tag pair:• <?php print date(“H:i”) ?>

23:18

Page 12: Web Programming with PHP (1)

• Free format - white space is ignored • Statements are terminated by semi-colon ; • Statements grouped by { … } • Comments begin with // or a set of comments /* */ • Assignment is ‘=’: $a=6• Relational operators are ,< , > == ( not a single equal) • Control structures include if (cond) {..} else { }, while (cond) { .. } ,

for(startcond; increment; endcond) { } • Arrays are accessed with [ ] - $x[4] is the 5th element of the array

$x – indexes start at 0 • Associative Arrays (hash array in Perl, dictionary in Java) are

accessed in the same way: $y[“fred”] • Functions are called with the name followed by arguments in a fixed

order enclosed in ( ) : substr(“fred”,0,2) • Case sensitive - $fred is a different variable to $FRED

C-like language

Page 13: Web Programming with PHP (1)

Function library (700+)

• Basic tasks– String Handling – Mathematics – random numbers, trig functions.. – Regular Expressions – Date and time handling – File Input and Output

• And more specific functions for-– Database interaction –

• MySQL, Oracle, Postgres, Sybase, MSSQL .. – Encryption – Text translation – Spell-checking – Image creation – XML

Page 14: Web Programming with PHP (1)

String Handling

• String literals (constants) enclosed in double quotes “ ” or single quotes ‘ ’

• Within “”, variables are replaced by their value: – called variable interpolation. “My name is $name, I think”

• Within single quoted strings, interpolation doesn’t occur • Strings are concatenated (joined end to end) with the

dot operator “key”.”board” == “keyboard” • Standard functions exist: strlen(), substr() etc • Values of other types can be easily converted to and

from strings – numbers implicitly converted to strings in a string context.

• Regular expressions be used for complex pattern matching.

Page 15: Web Programming with PHP (1)

http request/response cycle

Page 16: Web Programming with PHP (1)

3-tier architecture

PHP script

Remote services

Web Server (Apache, IIS)

Browser(IE, FireFox,

Opera)

Desktop (PC or MAC)

Database

Database Server

SQL

Client application

HTTP

HTML

Web Service

tables

DHTML

SMS

vision

touch

voice

SMS system

Page 17: Web Programming with PHP (1)

Learning PHP

• Start with just the basics, installing a script to output an HTML page

• Understand how PHP supports interaction with the Browser or other clients

• Understand how PHP supports integration with databases – MySQL

• Understand how PHP supports integration with other applications – Web services

Page 18: Web Programming with PHP (1)

PHP Resources- hand out : - php home : http://www.php.net- learning PHP : php @ w3 schools- code and examples :

php extension & application library (pear) : http://pear.php.net/resource index : http://php.resourceindex.com/weberdev :

http://www.weberdev.com/ArticlesSearch/Category/Beginner+Guides

phpexample : http://phpexamples.me/