Vous voulez voir cette page en français ? Cliquez ici.


or
Sign in to turn on 1-Click ordering.
More Buying Choices
Have one to sell? Sell yours here
Programming PHP
 
 

Programming PHP [Paperback]

Rasmus Lerdorf , Kevin Tatroe
3.5 out of 5 stars  See all reviews (33 customer reviews)
List Price: CDN$ 61.95
Price: CDN$ 39.03 & this item ships for FREE with Super Saver Shipping. Details
You Save: CDN$ 22.92 (37%)
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
Usually ships within 1 to 3 weeks.
Ships from and sold by Amazon.ca. Gift-wrap available.
‹  Return to Product Overview

Product Description

From Amazon

Coauthored by its creator, Programming PHP is a nitty-gritty guide to PHP development. PHP is an open-source scripting language used to build dynamic Web sites. In this title, the authors go step-by-step through the language, including brief coverage of common applications such as graphics or database work.

The first six chapters explain PHP essentials, including data types, functions, string manipulation, arrays and objects. Next comes a look at basic Web techniques, followed by an introduction to database access. There is a chapter on generating graphics with the GD extension library and another on creating Adobe PDF documents. The authors then show how to parse XML, and there is a section on security with some handy tips for protecting PHP sites. A chapter on application techniques looks at code libraries, performance tuning and handling errors. Next there is an explanation of how to build extensions to PHP using C, followed by a look at Windows issues such as COM and ODBC. Finally, there is a complete reference to the standard functions in PHP 4.0.

This is not an advanced programming book, but even experienced coders will discover new things about the language and get a clearer understanding of how PHP works. The specialist chapters such as those on XML or PHP extensions tend to be introductory, so readers will need further resources. For example, the database section is short, and would be best read alongside Web Database Applications with PHP and MySQL or another book with more detailed database coverage. Even so, this is a strong hands-on title that PHP developers will want to keep close at hand. ----Tim Anderson

Book Description

PHP is a simple yet powerful open-source scripting language for creating dynamic web content. The millions of web sites powered by PHP are testament to its popularity and ease of use. PHP is used by both programmers, who appreciate its flexibility and speed, and web designers, who value its accessibility and convenience. Programming PHP is an authoritative guide to PHP 4 and is filled with the unique knowledge of the creator of PHP, Rasmus Lerdorf. This book explains PHP language syntax and programming techniques in a clear and concise manner, with numerous examples that illustrate both correct usage and common idioms. The book also includes style tips and practical programming advice that will help you become not just a PHP programmer, but a good PHP programmer. Programming PHP covers everything you need to know to create effective web applications with PHP. Contents include:

  • Detailed information on the basics of the PHP language, including data types, variables, operators, and flow control statements
<li>Separate chapters on the fundamental topics of functions, strings, arrays, and objects</li> <li">Coverage of common PHP web application techniques, such as form processing and validation, session tracking, and cookies</li> <li>Material on interacting with relational databases, such as MySQL and Oracle, using the database-independent PEAR DB library</li> <li>Chapters on generating dynamic images, creating PDF files, and parsing XML files with PHP</li> <li>Advanced topics, like creating secure script, error handling, performance tuning, and writing your own C language extensions to PHP</li> <li>A handy quick reference to all the core functions in PHP and all the standard extensions that ship with PHP</li> </ul>

From the Publisher

Programming PHP is a comprehensive guide to PHP, a simple yet powerful language for creating dynamic web content. Filled with the unique knowledge of the creator of PHP, Rasmus Lerdorf, this book is a detailed reference to the language and its applications, including such topics as form processing, sessions, databases, XML, and graphics. Covers PHP 4, the latest version of the language.

About the Author

started the PHP Project back in 1995 and has been actively involved in PHP development ever since. Also involved in a number of other Open Source projects, Rasmus is a longtime Apache contributor and foundation member. He is the author of the first edition of the PHP Pocket Reference, and the co-author of Programming PHP.

Kevin Tatroe has been a Macintosh and Unix programmer for ten years. Being lazy, he's attracted to languages and frameworks that do much of the work for you, such as the AppleScript, Perl, and PHP languages and the WebObjects and Cocoa programming environments. Kevin, his wife Jenn, his son Hadden, and two cats live on the edge of the rural plains of Colorado, just far away enough from the mountains to avoid the worst snowfall, and just close enough to avoid tornadoes. The house is filled with LEGO creations, action figures, and other toys.

Excerpt. © Reprinted by permission. All rights reserved.

Chapter 5 - Arrays
As we discussed in Chapter 2, PHP supports both scalar and compound data types. In this chapter, we'll discuss one of the compound types: arrays. An array is a collection of data values, organized as an ordered collection of key-value pairs.
This chapter talks about creating an array, adding and removing elements from an array, and looping over the contents of an array. There are many built-in functions that work with arrays in PHP, because arrays are very common and useful. For example, if you want to send email to more than one email address, you'll store the email addresses in an array and then loop through the array, sending the message to the current email address. Also, if you have a form that permits multiple selections, the items the user selected are returned in an array.
Indexed Versus Associative Arrays
There are two kinds of arrays in PHP: indexed and associative. The keys of an indexed array are integers, beginning at 0. Indexed arrays are used when you identify things by their position. Associative arrays have strings as keys and behave more like two-column tables. The first column is the key, which is used to access the value.
PHP internally stores all arrays as associative arrays, so the only difference between associative and indexed arrays is what the keys happen to be. Some array features are provided mainly for use with indexed arrays, because they assume that you have or want keys that are consecutive integers beginning at 0. In both cases, the keys are unique--that is, you can't have two elements with the same key, regardless of whether the key is a string or an integer.
PHP arrays have an internal order to their elements that is independent of the keys and values, and there are functions that you can use to traverse the arrays based on this internal order. The order is normally that in which values were inserted into the array, but the sorting functions described later let you change the order to one based on keys, values, or anything else you choose.
Identifying Elements of an Array
You can access specific values from an array using the array variable's name, followed by the element's key (sometimes called the index) within square brackets:
$age['Fred']
$shows[2]
The key can be either a string or an integer. String values that are equivalent to integer numbers (without leading zeros) are treated as integers. Thus, $array[3] and $array['3'] reference the same element, but $array['03'] references a different element. Negative numbers are valid keys, and they don't specify positions from the end of the array as they do in Perl.
You don't have to quote single-word strings. For instance, $age['Fred'] is the same as $age[Fred]. However, it's considered good PHP style to always use quotes, because quoteless keys are indistinguishable from constants. When you use a constant as an unquoted index, PHP uses the value of the constant as the index:
define('index',5);
echo $array[index]; // retrieves $array[5], not $array['index'];
You must use quotes if you're using interpolation to build the array index:
$age["Clone$number"]
However, don't quote the key if you're interpolating an array lookup:
// these are wrong
print "Hello, $person['name']";
print "Hello, $person["name"]";
// this is right
print "Hello, $person[name]";
Storing Data in Arrays
Storing a value in an array will create the array if it didn't already exist, but trying to retrieve a value from an array that hasn't been defined yet won't create the array. For example:
// $addresses not defined before this point
echo $addresses[0]; // prints nothing
echo $addresses; // prints nothing
$addresses[0] = 'spam@cyberpromo.net';
echo $addresses; // prints "Array"
Using simple assignment to initialize an array in your program leads to code like this:
$addresses[0] = 'spam@cyberpromo.net';
$addresses[1] = 'abuse@example.com';
$addresses[2] = 'root@example.com';
// ...
That's an indexed array, with integer indexes beginning at 0. Here's an associative array:
$price['Gasket'] = 15.29;
$price['Wheel'] = 75.25;
$price['Tire'] = 50.00;
// ...
An easier way to initialize an array is to use the array( ) construct, which builds an array from its arguments:
$addresses = array('spam@cyberpromo.net', 'abuse@example.com',

'root@example.com');
To create an associative array with array( ), use the => symbol to separate indexes from values:
$price = array('Gasket' => 15.29,

'Wheel' => 75.25,

'Tire' => 50.00);
Notice the use of whitespace and alignment. We could have bunched up the code, but it wouldn't have been as easy to read:
$price = array('Gasket'=>15.29,'Wheel'=>75.25,'Tire'=>50.00);
To construct an empty array, pass no arguments to array( ):
$addresses = array( );
You can specify an initial key with => and then a list of values. The values are inserted into the array starting with that key, with subsequent values having sequential keys:
$days = array(1 => 'Monday', 'Tuesday', 'Wednesday',

'Thursday', 'Friday', 'Saturday', 'Sunday');
// 2 is Tuesday, 3 is Wednesday, etc.
If the initial index is a non-numeric string, subsequent indexes are integers beginning at 0. Thus, the following code is probably a mistake:
$whoops = array('Friday' => 'Black', 'Brown', 'Green');
// same as
$whoops = array('Friday' => 'Black', 0 => 'Brown', 1 => 'Green');

‹  Return to Product Overview

Amazon.ca Privacy Statement Amazon.ca Shipping Information Amazon.ca Returns & Exchanges