1 / 18

Web Programming with PHP (1)

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

afra
Télécharger la présentation

Web Programming with PHP (1)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web Programming with PHP (1)

  2. Pre-amble (1) What is programming? • 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)

  3. Pre-amble (2) Jackson Structured Programming - 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:

  4. 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.

  5. Pre-amble (4) Remembering the Web (1) 1993

  6. Pre-amble (5) Remembering the Web (2) Basic web 1.0 architecture & communication

  7. Pre-amble (6) stuff you (already) need to know Basic html, css & javascript • basic html • recognize and write basic xhtml • - the common tags? • - common form layout and data-types? • - well-formed? • - doctype declaration? • basic css • recognize and write basic css • basic css syntax? • the notions of external/embedded/inline styles? • - the basic idea behind the document object model (dom)? • basic javascript • recognize basic javascript syntax? • - know in what situations and tasks javascript is a useful technology?

  8. PHP Origins Originally 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 software First version PHP/FI released 1995 PHP 5.0 released July 2004 Current version is 5.3.0 PHP version 5.2.4 current at UWE PHP Version 6 due for release late 2009 / early 2010

  9. 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)?

  10. 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

  11. 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

  12. C-like language • 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

  13. 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

  14. 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.

  15. http request/response cycle

  16. 3-tier architecture voice DHTML HTTP SQL touch PHP script Browser (IE, FireFox, Opera) Database Web Server (Apache, IIS) Database Server vision HTML tables Desktop (PC or MAC) SMS Web Service SMS system Client application Remote services

  17. 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

  18. 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/

More Related