• History of PHP – Created by Rasmus Lerdorf in 1995 for tracking access to his resume – Originally a set of Perl scripts known as the “Personal Home Page” tools – Rewritten in C with
Trang 3– A language that combines elements of
Perl, C, and Java
Trang 4• History of PHP
– Created by Rasmus Lerdorf in 1995 for
tracking access to his resume
– Originally a set of Perl scripts known as the
“Personal Home Page” tools
– Rewritten in C with database functionality – Added a forms interpreter and released as PHP/FI: includes Perl-like variables, and
Trang 5• History of PHP (cont.)
– Rewritten again in and released as version 2.0
in November of 1997
– Estimated user base in 1997 is several
thousand users and 50,000 web sites served – Rewritten again in late 1997 by Andi Gutmans and Zeev Suraski
– More functionality added, database support, protocols and APIs
Trang 7• History of PHP (cont.)
– Rewritten again in 1997 by Andi Gutmans and Zeev Suraski
– More functionality added (OOP features),
database support, protocols and APIs
– PHP 3.0 is released in June 1998 with some
OO capability
– The core is rewritten in 1998 for improved
Trang 8• History of PHP (cont.)
– The core is rewritten in 1998 by Zeev and Andi and dubbed the “Zend Engine”
– The engine is introduced in mid 1999 and
is released with version 4.0 in May of 2000 – The estimated user base is hundreds of thousands of developers and several
million of web sites served
Trang 10• Netcraft Statistics
– 11,869,645 Domains, 1,316,288 IP Addresses
Trang 11• Performance*
– Zdnet Statistics
• PHP pumped out about 47 pages/second
• Microsoft ASP pumped out about 43 pages/second
• Allaire ColdFusion pumped out about 29
pages/second
• Sun Java JSP pumped out about 13 pages/second
* From PHP HOWTO, July 2001
Trang 12PHP Language Basics
• The Script Tags
– All PHP code is contained in one of several script tags:
• <?
// Some code
?>
• <?php // Some code here
?>
Trang 15PHP Language Basics
• Hello World!: An Example
– Like Perl, there is more than one way to do it
• <?php echo “Hello World!”; ?>
• <?php $greeting = “Hello World!”
printf(“%s”, $greeting);
php?>
Trang 17• define(“COMPANY”, “Acme Enterprises”);
• define(“YELLOW”, “#FFFF00”);
• define(“PI”, 3.14);
Trang 19PHP Language Basics
• Constants, Data Types and Variables
– Data types
• Integers, doubles and strings
– isValid = true; // Boolean– 25 // Integer– 3.14 // Double– ‘Four’ // String– “Total value” // Another string
Trang 22echo $arr["somearray"][6]; // 5 echo $arr["somearray"][13]; // 9 echo $arr["somearray"]["a"]; // 42
Trang 25Built-in Functions
• What comes In the box?
– Array Manipulator Functions
• sort, merge, push, pop, slice, splice, keys, count
– CCVS: Interface to Red Hat’s credit system – COM functions: Interface to Windows COM objects
– Date and Time Functions
• getdate, mkdate, date, gettimeofday, localtime,
Trang 26Built-in Functions
• What comes In the box?
– Directory Functions
• Platform independent
– Error Handling Functions
• Recover from warnings and errors
– Filesystem Functions
• Access flat files
• Check directory, link, and file status information
Trang 29Built-in Functions
– Database Functions (cont.)
Trang 30Built-in Functions
– POSIX Functions
• Manipulate process information
– Regular Expression Functions
• Uses POSIX regex
– Semaphore and Socket Functions
• Available only on Unix
– Session Management Functions
Trang 32$ConfigFile = "$ConfigPath/paperwork.conf";
$CountryList = "$DataPath/countries.txt";
$StateAbbrList = "$DataPath/usstateabbrs.txt";
Trang 33Tricks and Tips
• Coding
– Prototype your web pages first
• Separate the design of the site from the coding
– Turn repetitive code into functions
• Makes for more maintainable and reusable code
– Turn grunt code into functions
• Database access, configuration file access
Trang 34Tricks and Tips
Trang 35Tricks and Tips
Trang 36Tricks and Tips
• Development Tools
– Color coding editors
• vim, Emacs, Visual SlickEdit
– IDEs
• Windows
– Macromedia Dreamweaver – Allaire Homesite
– Zend’s PHPEdit
• Linux
Trang 37• Private, protected and abstract functions
• Private, protected and constant variables
• Namespaces
Trang 39– Newsgroups
• comp.lang.php