PHP Night by isbangee

VIEWS: 468 PAGES: 16

More Info
									PHP Night
March 29, 2005 by Nick Barrett

What 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)


Why learn PHP?


Named the 2004 programming language of the year!


http://www.tiobe.com/tpci.htm

Designed 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

Advantages 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!

Disadvantages of PHP
Error-handling  Debugging  Older versions have only partial support of object-oriented features  No client-side processing


Syntax


C-style language


If you’ve done Java, C, or JavaScript programming, you will find it very easy.
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_resized = 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 '<script language="JavaScript“>'; echo ' history.go(-1)'; echo '</script>'; }

<?php

?>

Data 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


Objects
<?php class Cart { var $items; // Items in our shopping cart

// Add $num articles of $artnr to the cart function add_item($artnr, $num) { $this->items[$artnr] += $num; }
// Take $num articles of $artnr out of the cart function remove_item($artnr, $num) { if ($this->items[$artnr] > $num) { $this->items[$artnr] -= $num; return true; } elseif ($this->items[$artnr] == $num) { unset($this->items[$artnr]); return true; } else { return false; } }

?>

}

Variables


PHP does not require explicit type definition when declaring variables—the type is determined by the context! Very useful when creating code and reusing variables
<?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! ?>



Control structures
If/Else statements  For loops  While loops  For each loops  Switch statements


Processing 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?variable=value) $_POST[] is a global array created by the web server when a form is sent via the POST method



Development Environments
Dreamweaver MX 2004  Eclipse 3.0  PHP Coder  Notepad  Lots of other free and commercial products.


Examples
“Hello world”  Form handling  Interacting with a MySQL database  Authentication system (sessions)  Advanced topics


Content management systems  Object-oriented design  Image editing


Online 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


Books


								
To top