Title: PHP Night
1PHP Night
- March 29, 2005
- by Nick Barrett
2What is PHP?
- Stands for Pre-hypertext processor
- Primarily a server-side programming language
(also command-line) - Available on nearly every platform
- Integrates well with a variety of webs servers
(Apache, Microsoft IIS, etc.) - Open-source project started in 1994.
- Became popular with version 3.0 (now at 5.03)
3Why learn PHP?
- Named the 2004 programming language of the year!
- http//www.tiobe.com/tpci.htm
4Designed for web development
- "PHP was built with the needs of Web developers
in mind... Unlike other cumbersome,
overhead-laden approaches, PHP is lightweight and
focused on the Web - where it can solve complex
problem scenarios quicker and more easily than
comparable technologies. - - Intranet Design Magazine
5Advantages of PHP
- Extremely quick development
- If it takes about 3 months to code a web
application in C, then using PHP you can
develop the same web application in just 4 days!!
And with Zend optimizer, the speed of execution
of PHP will be very close to that of equivalent
C program!! - Well-documented
- Large libraries and repositories of code, free to
share - Very fast execution (considered the fastest
scripting language) - Interacts with nearly any database
- Oracle, dBase, FrontBase, PostgreSQL, FilePro,
mSQL, MS-SQL, Sybase, IBM DB2, MySQL, ODBC,
basically anything!
6Disadvantages of PHP
- Error-handling
- Debugging
- Older versions have only partial support of
object-oriented features - No client-side processing
7Syntax
- C-style language
- If youve done Java, C, or JavaScript
programming, you will find it very easy.
lt?php include("dbconnect.php") photoID
trim(HTTP_GET_VARS'photoID') rs
mysql_query("select from photos where photoID
'".photoID."'") row mysql_fetch_array(rs)
del_orig unlink(row'original') del_res
ized unlink(row'resized') del_thumbnail
unlink(row'thumbnail') if(del_orig
del_resized del_thumbnail) rs2
mysql_query("delete from photos where photoID
'".photoID."'") echo 'ltscript
language"JavaScriptgt' echo
' history.go(-1)' echo 'lt/scriptgt' ?gt
8Data types
- There are 8 primitive data types
- Boolean (true/false)
- Integer (3, 5, 1242)
- Float (0.32, 3.14259)
- String (ASM, Marriott School)
- Array (5, 3, 5, Apples, 5, true)
- Object
- Resource
- NULL
9Objects
- lt?phpclass Cart   var items // Items in
our shopping cart  // Add num articles of
artnr to the cart  function add_item(artnr,
num)     this-gtitemsartnr num Â
  // Take num articles of artnr out of the
cart  function remove_item(artnr, num)   Â
 if (this-gtitemsartnr gt num)      Â
this-gtitemsartnr - num      return
true    elseif (this-gtitemsartnr
num) Â Â Â Â Â Â unset(this-gtitemsartnr)Â Â
    return true    else      Â
return false      - ?gt
10Variables
- PHP does not require explicit type definition
when declaring variablesthe type is determined
by the context! - Very useful when creating code and reusing
variables - lt?php
- foo "0" Â // foo is string
- foo 2 Â // foo is now an integer (2)
- foo foo 1.3 Â // foo is now a float
- foo true // foo is now a boolean
- foo array(4, 2, 5) // foo is now an array!
- ?gt
11Control structures
- If/Else statements
- For loops
- While loops
- For each loops
- Switch statements
12Processing web-based data
- List of global variables from phpinfo()
- http//128.187.110.210/info.php
- GET and POST arrays
- _GET is a global array of variables passed in
via the URL (page.php?variablevalue) - _POST is a global array created by the web
server when a form is sent via the POST method
13Development Environments
- Dreamweaver MX 2004
- Eclipse 3.0
- PHP Coder
- Notepad
- Lots of other free and commercial products.
14Examples
- Hello world
- Form handling
- Interacting with a MySQL database
- Authentication system (sessions)
- Advanced topics
- Content management systems
- Object-oriented design
- Image editing
15Online Resources
- THE place to go www.php.net/docs.php
- Installing PHP 4 with Apache on Windows
- Installing PHP 5 with Apache 2.0 on Windows
- Great overall tutorial on getting started with
beginning/intermediate PHP
16Books