SKIP THE SHIPPING
Use code NOSHIP during checkout to save 40% on eligible eBooks, now through January 5. Shop now.
Register your product to gain access to bonus material or receive a coupon.
Helps students understand syntax.
Provides students with the most up-to-date programming features.
Student does not need to key-in sample programs.
Provides the student with a tutorial and reference.
Foreword by Andi Gutmans
Praise for the first edition:
Core PHP Programming has proved itself an invaluable technical reference. I highly recommend it for beginners as well, since the official PHP manual often assumes too much knowledge on behalf of the user. Leon's strength is that he does not try to sound more technical than needed, simply for the sake of impressing other programmers. In short, a must-have for any PHP user, beginning or advanced!
Zack Beatty, Enterprise Web Engineer
The experienced developer's guide to PHP!
Master PHP 4, the open source, high-performance, cross-platform solution for server-side scripting!
Core PHP Programming, Second Edition is the #1 practical guide to PHP 4 for Web developers. With the guidance of top PHP developer Leon Atkinson, you'll learn everything you'll need to build robust, fast Web applications and deploy them on leading Web servers, from Apache to Microsoft Internet Information Server.
Atkinson covers PHP syntax, the key building blocks of PHP scripts, and every PHP function, including I/O, data, and math functions, time, date, configuration, database, graphics, and network functions. He presents PHP at work in sample code that demonstrates sorting, searching, parsing, string evaluation, and more. You'll even find detailed, real-world insights into PHP 4 program design and debugging!
Core PHP Programming delivers
CD-ROM includes PHP 4 source code and Windows binaries plus all the code examples from the book!
Click here for a sample chapter for this book: 0130893986.pdf
I. PROGRAMMING WITH PHP.
1. An Introduction to PHP.The Origins of PHP. What Makes PHP Better than Its Alternatives. Interfaces to External Systems. How PHP Works with the Web Server. Hardware and Software Requirements. Installation on Apache for UNIX. Installation on IIS for Windows NT. Editing Scripts. Algorithms. What a PHP Script Looks Like. Saving Data for Later. Receiving User Input. Choosing between Alternatives. Repeating Code. Conclusion.
2. Variables, Operators, and Expressions.Identifiers. Data Types. Variable Creation and Scope. Assigning Values to Variables. Retrieving Values. Freeing Memory. Constants. Operators. Logical and Relational Operators. Bitwise Operators. Miscellaneous Operators. Assignment Operators. Expressions.
3. Control Statements.True and False. The if Statement. The ? Operator. The switch Statement. Loops. The while Statement. The break Statement. The continue Statement. The do while Statement. The for Statement. The foreach Statement. exit, die, and return. Evaluation of Boolean Expressions.
4. Functions.Declaring a Function. The return Statement. Scope and the global Statement. Arguments. Recursion. Dynamic Function Calls.
5. Arrays.Single-Dimensional Arrays. Indexing Arrays. Initializing Arrays. Multidimensional Arrays. Casting Arrays. Referencing Arrays Inside Strings.
6. Classes and Objects.Defining a Class. Creating an Object. Accessing Properties and Methods.
7. I/O and Disk Access.HTTP Connections. Writing to the Browser. Output Buffering. Environment Variables. Getting Input from Forms. Cookies. File Uploads. PUT Method Requests. Reading and Writing to Files. Sessions. The include and require Functions.
II. FUNCTIONAL REFERENCE.
8. I/O Functions.Sending Text to the Browser. Output Buffering. Files. Compressed File Functions. POSIX. Debugging. Session Handling. Shell Commands. HTTP Headers. Network I/O. FTP.
9. Data Functions.Data Types, Constants, and Variables. Arrays. Hashing. Strings. Encoding and Decoding. Encryption. Regular Expressions. Perl-Compatible Regular Expressions.
10. Mathematical Functions.Common Math. Random Numbers. Arbitrary-Precision Numbers.
11. Time, Date, and Configuration Functions.Time and Date. Alternative Calendars. Configuration.
12. Image Functions.Analyzing Images. Creating JPEG, PNG, and WBMP Images.
13. Database Functions.dBase. DBM-style Database Abstraction. filePro. Informix. InterBase. mSQL. MySQL. ODBC. Oracle. Postgres. Sybase.
14. Miscellaneous Functions.Apache. Aspell. COM. Gettext. IMAP. Java. LDAP. Semaphores. Shared Memory. SNMP. WDDX. XML.
III. ALGORITHMS.
15. Sorting, Searching, and Random Numbers.Sorting. Bubble Sort. Quicksort. Built-In Sorting Functions. Sorting with a Comparison Function. Searching. Indexing. Random Numbers. Random Identifiers. Choosing Banner Ads.
16. Parsing and String Evaluation.Tokenizing. Regular Expressions. Defining Regular Expressions. Using Regular Expressions in PHP Scripts.
17. Database Integration.Building HTML Tables from SQL Queries. Tracking Visitors with Session Identifiers. Storing Content in a Database. Database Abstraction Layers.
18. Network.HTTP Authentication. Controlling Browser Cache. Setting Document Type. Email with Attachments. Verifying an Email Address.
19. Generating Graphics.Dynamic Buttons. Generating Graphs on the Fly. Bar Graphs. Pie Charts. Stretching Single-Pixel Images.
IV. SOFTWARE ENGINEERING.
20. Integration with HTML.Sprinkling PHP within an HTML Document. Using PHP to Output All HTML. Separating HTML from PHP. Creating <W9S> Fields. Passing Arrays in Forms.
21. Design.Writing Requirements Specifications. Writing Design Documents. Using CVS. Modularization Using include. FreeEnergy. FastTemplate. Midgard. Ariadne. Preserving State and Providing Security. Cloaking. URLs Friendly to Search Engines. Running a Script Regularly.
22. Efficiency and Debugging.Measuring Performance. Fetching Database Query Results. When to Store Content in a Database. In-Line Debugging. Remote Debugging. Simulating HTTP Connections.
Appendix A.My first inkling that I might like to write a book about PHP was born out of the frustration I felt with the original PHP manual. It was a single, large HTML file with all the functions in alphabetical order. It was also on a Web server thousands of miles away from me in Canada, so it was slow to show up in my browser, even across a T1 connection. It wasn't long before it was saved on my desktop. After struggling for several months, it started to dawn on me that I could probably organize the information into a more usable format. Around that time the next version of PHP began to take shape, and with it a new manual was developed. It was organized around PHP's source code but was less complete than the old PHP manual. I contributed descriptions for some of the missing functions, but I still had the idea to write my own manual. In the spring of 1998 Prentice Hall PTR gave me the opportunity to do so. It is an honor for my book to be among Prentice Hall classics such as The C Programming Language by Brian Kernighan and Dennis Ritchie.
This book assumes a certain familiarity with the Internet, the Web, and HTML programming, but it starts with the most basic ideas of programming. It will introduce you to concepts common to all programming languages and how they work in PHP. You can expect this book to teach you how to create rich, dynamic Web sites. You can also expect it to remain on your desk as a reference for how PHP works, or even as a recipe book for solving common design problems.
This book is not for dummies, nor is it for complete idiots. That you are considering PHP is a great indication of your intelligence, and I'd hate to insult it. Some of the ideas in this book are hard to understand. If you don't quite get them the first time, I encourage you to reread and experiment with the examples.
If you are uncomfortable writing HTML files, you may wish to develop this skill first. Marty Hall's Core Web Programming provides an excellent introduction. Beyond HTML, numerous other topics I touch on fall out of scope. Whenever I can, I suggest books and Web sites that provide more information. There are even some aspects of PHP that range too far from the focus on writing PHP scripts. An example is writing extensions for PHP in C. This involves a healthy knowledge of C programming that I cannot provide here. Related to this is compiling and installing PHP. I attempt to describe the process of installing PHP, which can involve compiling the source code, but I can't attempt to pursue all the different combinations of operating system, Web servers, and extensions. If you are comfortable running make
files, you will find the information that comes with the PHP source code more than adequate.
Along with the explanation text I've provided real-world examples. Nothing is more frustrating than trying to adapt some contrived academic problem to the Web site you must have working by the end of the week. Some of the examples are based on code from live Web sites I have worked on since discovering PHP in 1997. Others are distilled from the continual discussion being conducted on the PHP mailing lists.
This book is organized into four main sections: an introduction to programming; a reference for all the functions in PHP; a survey of common programming problems; and finally a guide for applying this knowledge to Web site development. The first section deals with the issues involved with any programming language: what a PHP script looks like; how to control execution; how to deal with data. The second section organizes the functions by what they do and gives examples of their use. PHP offers many functions, so this section is larger than the rest. The third section deals with solving common programming problems such as sorting and generating graphics. The last section offers advice about how to create a whole Web site with PHP.
I've chosen a few conventions for highlighting certain information, and I'm sure you will find them obvious, but for the sake of clarity I'll spell them out. Whenever I use a keyword such as the name of a script or a function, I place it in a monospace font. For example, I may speak about the print
function. Another convention I've used is to place email addresses and Web addresses inside angle brackets. Examples are the email address by which you can contact me, <corephp@leonatkinson.com>
, and my Web site,
<http://www.leonatkinson.com/>