Download presentation
Presentation is loading. Please wait.
1
PHP Presented by Christine Fang and Ian Stuart ● CS616 Spring 2003
2
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. What is PHP?
3
The code is written in files containing a mixture of PHP instructions and HTML code. PHP between Programs run on a web servers and return HTML code readable by any browser. No client-side plug-ins are required. How does it work?
4
Web Server/Browser Interact with PHP
5
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 What can we do with PHP?
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
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 Data Types
8
<?php $myClass = “CS616”; echo “Welcome to $myClass”; ?> A Very Simple Example
9
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. Handling HTML Forms
10
Numerically-Indexed Arrays Associative (String-Indexed) Arrays $treeMember["YearOfBirth"] = 1913; Non-Sequential Arrays $employeeNames[268] = "Fang"; $employeeNames[145] = "Stuart"; Multidimensional Arrays PHP: Arrays
11
Conditional/Branching Statements –if / else / else if –switch / case Loops and iterations –while and do/while –for and foreach loops –list and each functions PHP Control Structures
12
foreach ($myArray As $myArrayElement) { …iterate through each $myArrayElement } foreach ($myArray As $myArrayIndex => $myArrayElement) { …iterate through each $myArrayIndex that corresponds to each $myArrayElement } PHP: foreach Loops
13
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 } PHP: list and each Functions
14
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 Modularization and OO Support
15
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) PHP Objects
16
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) Regular Expressions in PHP
17
$validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@". "[a-z0-9]+([\.][a-z0-9]+)*". "\.[a-z]{2,}", $theEmailAddress); Regular Expressions in PHP Huh…?
18
$validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@". "[a-z0-9]+([\.][a-z0-9]+)*". "\.[a-z]{2,}", $theEmailAddress); Regular Expressions in PHP kathleen.chou@thewebgoddess.org
19
$validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@". "[a-z0-9]+([\.][a-z0-9]+)*". "\.[a-z]{2,}", $theEmailAddress); Regular Expressions in PHP 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
$validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@". "[a-z0-9]+([\.][a-z0-9]+)*". "\.[a-z]{2,}", $theEmailAddress); Regular Expressions in PHP 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
$validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@". "[a-z0-9]+([\.][a-z0-9]+)*". "\.[a-z]{2,}", $theEmailAddress); Regular Expressions in PHP kathleen.chou@thewebgoddess.org …followed by the @ symbol…
22
$validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@". "[a-z0-9]+([\.][a-z0-9]+)*". "\.[a-z]{2,}", $theEmailAddress); Regular Expressions in PHP kathleen.chou@thewebgoddess.org …followed by one or more blocks of text using the same patterns used before (the server/domain names)…
23
$validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@". "[a-z0-9]+([\.][a-z0-9]+)*". "\.[a-z]{2,}", $theEmailAddress); Regular Expressions in PHP 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
$validEmail = eregi ( "^[a-z0-9]+([\.][a-z0-9]+)*@". "[a-z0-9]+([\.][a-z0-9]+)*". "\.[a-z]{2,}", $theEmailAddress); Regular Expressions in PHP 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 provides connectivity for several database systems and sources, including (in part): –Unified ODBC –Microsoft SQL Server –MySQL –Oracle –Sybase –Informix PHP and Databases
26
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 PHP vs. Java and JSP
27
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. PHP vs. Java and JSP
28
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. PHP vs. ASP
29
Revised Alta Vista results, March 6, 2002. Source: http://php.weblogs.com/popularity Market Share
30
Revised Alta Vista results, March 6, 2002. Source: http://php.weblogs.com/popularity
31
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 PHP Resources
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.