Beginning PHP4
Table of Contents
Introduction 1
Why PHP4? 2
The Prompt 2
What Do I Need To Use This Book? 3
PHP4 Resources 4
Conventions 4
Downloading the Source Code 5
Support & Errata 5
Online Forums at p2p.wrox.com 6
Checking the Errata Online at www.wrox.com 6
Wrox Developers Membership 6
Finding Errata on the Web Site 8
Adding Errata and Obtaining e-Mail Support 9
Customer Support 9
Editorial 9
The Authors 9
What We Cant Answer 9
How to Tell Us Exactly What You Think 9
Chapter 1: Installation 11
Installing PHP4 on Windows 95 and 98 13
Obtaining PWS 13
Setting Up PWS 15
Installing PHP4 Alongside PWS 17
Installing PHP4 on Windows NT and 2000 19
Installing PHP4 Alongside IIS 24
Installing PHP4 on Linux and Other UNIXes 28
Choosing Your Installation Method 29
Obtaining RPMs 29
Which Packages Do We Need? 30
Configuring and Starting Apache with PHP4 31
ii
Testing Your Installation 34
Chapter 2: Writing PHP Programs 39
An Example PHP Program 40
Viewing a Web Page 44
Client-Server 44
Internet Protocols 44
The HTTP Protocol 45
The HTTP Request 46
The HTTP Response 48
Where PHP Comes Into This 49
Server-Side Scripting 50
Identifying a PHP Script 51
Caching 51
Variables 52
Data Types 55
String Data Type 55
Numeric Data Types 58
Constants 63
The Define Keyword 64
Initialization 64
Conversions 65
Type Casting 67
gettype and settype 67
isset, unset, and empty 68
Environment Variables 68
Summary 69
Chapter 3: Getting Data from the Client 71
Web Forms 72
The FORM Tag 72
Attributes of FORM 72
ACTION 72
METHOD 73
HTML Form Controls and PHP 76
Text Fields (Text Boxes) 76
Text Areas 80
Check Boxes 82
Radio Buttons 88
List Boxes 91
Hidden Controls 95
Passwords 99
Submit Buttons and Reset Buttons 99
Using Values Returned From Forms In Your PHP Scripts 100
Summary 106
Chapter 4: Decision Making 109
Conditional or Branching Statements 110
An Example of Branching in Day to Day Life 110
If Statements 111
Boolean Values 112
iv
Boolean operators 112
Combining Operators 123
v
Multiple Conditions else and elseif 127
Nesting If Statements 129
Switch Statements 135
Form Validation 140
Summary 144
Chapter 5: Loops and Arrays 147
Loops 148
while Loops 148
do while Loops 155
for Loops 159
Arrays 165
Initialization of Arrays 165
Iterating Through an Array 167
Iterating Through Non-Sequential Arrays 172
Iterating Through String-Indexed Arrays 176
Sorting Arrays 177
sort() 177
asort() 178
rsort() and arsort() 179
ksort() 179
Miscellaneous Array Functions 180
array_push() and array_pop() 180
Implode and Explode 180
HTTP_GET_VARS and HTTP_POST_VARS 182
Multi-dimensional Arrays 182
Practical Demonstration of Arrays 183
New Loop and Array Features in PHP4 188
Array Multisorting 188
foreach Loops 189
Summary 191
Chapter 6: Organizing Your Code 193
Whats So Great About Code Reuse? 194
Modularization 194
Functions 194
Defining and Calling Functions 195
Switching Functions 201
Assignin…
Yorum Yok.