1 / 31

PHP

PHP. Presented by Christine Fang and Ian Stuart ● CS616 Spring 2003. What is PHP?. PHP - the “ P HP H ypertext P reprocessor” It’s an open-source programming language for building dynamic, interactive web sites. Devised by Rasmus Lerdorf in 1994. PHP is a project of the Apache Foundation.

chesna
Download Presentation

PHP

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. PHP Presented by Christine Fang and Ian Stuart ●CS616 Spring 2003

  2. What is PHP? • PHP - the “PHP Hypertext Preprocessor” • It’s an open-source programming language for building dynamic, interactive web sites. • Devised by Rasmus Lerdorf in 1994. • PHP is a project of the Apache Foundation. • In technical terms, PHP is a cross-platform, HTML-embedded, server-side web scripting language.

  3. How does it work? • The code is written in files containing a mixture of PHP instructions and HTML code. • PHP between <?php tag and ending tag?> • Programs run on a web servers and return HTML code readable by any browser. • No client-side plug-ins are required.

  4. Web Server/Browser Interact with PHP

  5. What can we do with PHP? • PHP can be used to write the web sites which anyone familiar with the Web uses every day: e-commerce sites, search engines, etc. • Allows custom pages for clients • Supports back-end database connectivity

  6. Server software A PHP compatible web server PHP4 A relational database system Client software A web browser A text editor, such as Notepad, Emacs, vi, BBEdit, and so on. What software do we need? www.firepages.com.au

  7. Data Types Like HTML, PHP variables are not strongly typed: they don’t need to be cast by the programmer. • String (text) • integer (numeric) • double (numeric) • array • object

  8. A Very Simple Example <html><head></head> <body> <?php $myClass = “CS616”; echo “Welcome to $myClass”; ?> </body> </html>

  9. Handling HTML Forms • GET method and POST method • Most common HTML form controls: text boxes, checkboxes, radio buttons, listboxes, hidden fields, passwords and buttons. • The ACTION attribute is used to specify which page we go to once the form is submitted. The .php file suffix indicates that the page is sent to the PHP script engine.

  10. PHP: Arrays • Numerically-Indexed Arrays • Associative (String-Indexed) Arrays $treeMember["YearOfBirth"] = 1913; • Non-Sequential Arrays $employeeNames[268] = "Fang"; $employeeNames[145] = "Stuart"; • Multidimensional Arrays

  11. PHP Control Structures • Conditional/Branching Statements • if / else / else if • switch / case • Loops and iterations • while and do/while • for and foreach loops • list and each functions

  12. PHP: foreach Loops foreach ($myArray As $myArrayElement) { …iterate through each $myArrayElement } foreach ($myArray As $myArrayIndex => $myArrayElement) { …iterate through each $myArrayIndex that corresponds to each $myArrayElement }

  13. PHP: list and each Functions • Useful for iterating through associative and nonsequential arrays: while (list($index, $elementData) = each($theArray)) { …iterate through the array, with access to the indices and elements }

  14. Modularization and OO Support • PHP “modules” are functions • Pass variables by value or by reference • No function overloading, but default values for parameters can be defined • “Include” files • Simple import of code from other files • Works within conditional constructs • Limited support for objects

  15. PHP Objects • PHP was not originally intended to be OO • Now supports classes • Class and instance variables • Inheritance (subclasses) • Limited polymorphism (no overriding) • Objects can be serialized/deserialized (example: session management)

  16. Regular Expressions in PHP • Allow pattern recognition in data • Similar notation to Perl or Python • Convenient for string manipulation: • Escaping special characters (i.e. backslashes) • Parsing and matching text • Data verification (URLs, e-mail, passwords)

  17. Regular Expressions in PHP $validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@" . "[a-z0-9]+([\.][a-z0-9]+)*" . "\.[a-z]{2,}", $theEmailAddress); Huh…?

  18. Regular Expressions in PHP $validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@" . "[a-z0-9]+([\.][a-z0-9]+)*" . "\.[a-z]{2,}", $theEmailAddress); kathleen.chou@thewebgoddess.org

  19. Regular Expressions in PHP $validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@" . "[a-z0-9]+([\.][a-z0-9]+)*" . "\.[a-z]{2,}", $theEmailAddress); kathleen.chou@thewebgoddess.org The string $theEmailAddress must begin with a block of text Containing alphanumeric characters (A to Z, a to z, 0-9)…

  20. Regular Expressions in PHP $validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@" . "[a-z0-9]+([\.][a-z0-9]+)*" . "\.[a-z]{2,}", $theEmailAddress); kathleen.chou@thewebgoddess.org …followed by zero or more blocks of text that must start with a period and then at least one alphanumeric character…

  21. Regular Expressions in PHP $validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@" . "[a-z0-9]+([\.][a-z0-9]+)*" . "\.[a-z]{2,}", $theEmailAddress); kathleen.chou@thewebgoddess.org …followed by the @ symbol…

  22. Regular Expressions in PHP $validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@" . "[a-z0-9]+([\.][a-z0-9]+)*" . "\.[a-z]{2,}", $theEmailAddress); kathleen.chou@thewebgoddess.org …followed by one or more blocks of text using the same patterns used before (the server/domain names)…

  23. Regular Expressions in PHP $validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@" . "[a-z0-9]+([\.][a-z0-9]+)*" . "\.[a-z]{2,}", $theEmailAddress); kathleen.chou@thewebgoddess.org …followed by a block of text that must begin with a period and then consist of at least two letters (the domain suffix).

  24. Regular Expressions in PHP $validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@" . "[a-z0-9]+([\.][a-z0-9]+)*" . "\.[a-z]{2,}", $theEmailAddress); kathleen.chou@thewebgoddess.org If the pattern matches, $validEmail equals true; otherwise it’s false. (In reality, we’d also check for characters like underscores and hyphens.)

  25. PHP and Databases • PHP provides connectivity for several database systems and sources, including (in part): • Unified ODBC • Microsoft SQL Server • MySQL • Oracle • Sybase • Informix

  26. PHP vs. Java and JSP • PHP doesn’t require client-side capabilities besides an HTML-enabled browser. • PHP requires less communication overhead than Java and JSP. • PHP lacks some features like custom tags and JavaBeans. • Better OO in Java and JSP

  27. PHP vs. Java and JSP • Consider Java/JSP for larger projects requiring reusable modules and large libraries. • Consider PHP when processing performance is a primary concern, or when rapid application development is needed.

  28. PHP vs. ASP • PHP uses a C-like syntax; ASP is driven by VBScript. • ASP is generally slower due to overhead; PHP uses its own memory space. • PHP is open source (read: free) while ASP is a proprietary commercial product.

  29. Market Share Revised Alta Vista results, March 6, 2002. Source: http://php.weblogs.com/popularity

  30. Market Share Revised Alta Vista results, March 6, 2002. Source: http://php.weblogs.com/popularity

  31. PHP Resources • The official PHP site: www.php.net • PHP Builder: http://www.phpbuilder.com • PHP Developer’s Network: http://www.devnetwork.net • PHPFreaks.com: http://www.phpfreaks.com • Codewalkers.com: http://codewalkers.com

More Related