
- •Initializing with Constructor Functions . . . . .
- •Into a Web page as a separate section. Although JavaScript code can
- •Is that standard php script delimiters are guaranteed to be available
- •In the block. Any text or lines between the opening /* characters and
- •2.7541 Are not integers; they are floating-point numbers. A floating-
- •Value 300
- •Is a value of 2.5, because 6 goes into 15 exactly 2.5 times. But if you
- •IsEven.Php.
- •Ing example,
- •Ing curly brace is on its own line following the function statements.
- •In php 3 and earlier, it was necessary to put a function definition
- •Is called an iteration. When the conditional expression evaluates
- •Including Files
- •13. Close your Web browser window.
- •Including Files
- •In php, you can also use two operators to combine strings. The first
- •Xhtml source code gen-
- •Input. Php provides several functions for manipulating the case of a
- •Is uppercase. If you need the reverse of ucfirst(), the lcfirst()
- •In some situations, you will need to find and extract characters and
- •Information Interchange, or ascii, which are numeric represen-
- •In comparison, the following preg_match() function returns a value
- •In the pattern is optional. The following code demonstrates how to
- •Values; any strings you validate against a regular expression must
- •Value of 1 because the top-level domain contains a valid value of .Com.
- •Is submitted using the “post” method, the form data is embedded in
- •Validating String Data
- •Xhtml tags or character entities. The message field is a text string
- •Value of the header element. For example:
- •Xhtml code within a php script section.
- •Is typically the person who created the resource. Otherwise, the net-
- •If even a single character of the Web page is sent prior to sending
- •Variables to the file_put_contents() function.
- •Xhtml hyperlink. To download a file from outside the xhtml
- •If...Else statement to display the appropriate version of the mes-
- •Iterating Through an Array
- •Iterating Through an Array
- •In Chapter 2, you learned how to use a foreach statement to iterate
- •Iterating Through an Array
- •Iterating Through an Array
- •In comparison, the following code declares and initializes
- •If ((!file_exists("MessageBoard/messages.Txt"))
- •Values from the array to create a thumbnail gallery of images in which
- •Introduction to Databases
- •Including php, allow you to create Web pages that can read and write
- •Introduction to Databases
- •Information that can be organized into ordered sets of data, and
- •Information. Each recipe in a recipe database, for instance, is a single
- •Introduction to Databases
- •Index, which identifies records in a database to make retrievals and
- •In a single table. However, you might want to break the information
- •Into multiple tables to better organize it into logical sets. Another
- •Information in one of the tables confidential and accessible only by
- •Is the employee information table from Figure 7-1. The related table
- •Is a payroll table that contains confidential salary and compensation
- •Information. Notice that each table contains an identical number of
- •Introduction to Databases
- •Introduction to Databases
- •In a junction
- •Introduction to Databases
- •In a relational format is called a relational database management
- •Is a standard data manipulation language among many dbmSs.
- •Into the query area at the top of the screen or by dragging tables and
- •It is important to understand that even though many dbmSs sup-
- •Introduction to Databases
- •If you ever
- •Is. In comparison, the bigint data type stores integer values between
- •5 Rows in set (0.00 sec)
- •Int);[enter ]
- •Important, these two tabs can cause you to lose all of the data in the
- •Internet Explorer to export the table, click the Save button in the File
- •Ifies the table being changed and the change to make.
- •It easier for you to write php code that can be used with a variety of
- •Information about queries that match one of the following formats:
- •Various types of actions, depending on the type of query.
- •Include fields for the date and time of the flight, flight number, and
- •In the ChineseZodiac folder and upload the file to the server. Open
- •Including white space,
- •Information on a Web server. When you start a new session, the
- •Introduction to Object-Oriented Programming
- •Introduction to Object-Oriented
- •Variables associated with an object are called properties or attributes.
- •In the Loan object example, a function that calculates the number of
- •Introduction to Object-Oriented Programming
- •Introduction to Object-Oriented Programming
- •Include instances of objects inherit the object’s functionality.
- •In this chapter, you will create the Web site for an online order form
- •In an online store application. The application includes information
- •Ity of building a working online store. Online store classes are very
- •Information and products. The OnlineStore class requires that store
- •Information is stored in a table containing six fields: storeId, name,
- •Information. Instead, the class simply uses session iDs to keep track
- •Variable and function as necessary, without bothering with all this
- •In a class
- •Is developed. Imagine what would happen if Microsoft distributed
- •Ing class is invalid because it does not include an access specifier:
- •If they will not be supported by future xhtml versions or are not
- •Xhtml standards. To review the guide of current w3c css specifi-
- •Information to remind yourself or others of what the code is doing. A
- •Xhtml document to the external style sheet. This link informa-
- •If you select Apache from the WampServer menu and select Service
- •Ing code uses the number_format() function to add comma separa-
- •In data that a user submits to a php script.
- •Value of “On” and the display_startup_errors directive is assigned
- •Instead. By looking at the source code, you could see that the value of
- •Ing engine can even help locate logic errors.
- •In Chapter 8, along with the equivalent mssql_* functions, where
- •Inline styles, 632
- •Xhtml, 620–635 (continued)
Reinforcement
Exercises
5.
Save
the document as SingleFamilyHome.php in the
Projects
folder for Chapter 1, upload the document to the
server,
and then validate it with the W3C XHTML Validator.
After
the document is valid, close it in your text editor, and
then
open it in your Web browser to see how it renders. You
should
see the text “The current median price of a single fam-
ily
home in Pleasanton, CA is $399,500.00.” displayed on the
screen.
Close
your Web browser window.
71
6.
Exercise
1-4
Write
a script that assigns the days of the week to an array named
$Days[].
Use output statements to display “The days of the week in
English
are: ” along with the values in the $Days[]
array.
Following
the
output statements, reassign the values in the $Days[]
array
with
the days of the week in French. Sunday is Dimanche, Monday
is
Lundi, Tuesday is Mardi, Wednesday is Mercredi, Thursday is
Jeudi,
Friday is Vendredi, and Saturday is Samedi. Then use output
statements
to display “The days of the week in French are: ” along
with
the French values in the $Days[]
array.
Save the document as
DaysArray.php.
Exercise
1-5
You
can use the round(),
ceil(),
and floor()
functions
to
round
a fraction up or down to the nearest whole number. The
round()
function
rounds a fraction to the nearest whole number,
the
ceil()
function
rounds a fraction up to the nearest whole num-
ber,
and the floor()
function
rounds a fraction down to the nearest
whole
number. Write a script that demonstrates the use of these
functions.
Save the document as RoundedValues.php.
Exercise
1-6
Write
a script that uses a conditional operator to determine whether
a
variable contains a number and whether the number is even. You
need
to use the is_numeric()
function
and the conditional operator.
For
floating-point numbers, you need to use the round()
function
to
convert
the value to the nearest whole number. Save the document asIsEven.Php.
CHAPTER
1
Getting
Started with PHP
Discovery
Projects
At
the end of each chapter, you will apply the concepts you have
learned
to a single, ongoing project. When completed, this project
will
be a comprehensive Web site that demonstrates application of
many
of the PHP concepts covered in the textbook. The Chinese
zodiac
theme was selected because it lends itself well to many of
the
PHP constructs you will learn in future chapters. All files for the
Chinese
Zodiac site will be saved in a folder named ChineseZodiac in
the
root Web folder on the server.
The
following Discovery Projects will prepare you for the design and
development
of your site:
72
Discovery
Project 1-1
If
your site
layout is
designed to
have but-
tons at the
top and a text navigation
bar on the left, you will
want a banner that is
approximately 392×72
pixels. If you plan to have
both the button naviga-
tion and text navigation at
the top, you will want a
banner that is approxi-
mately 468×60 pixels.
You will need to select a color scheme and design or find free
Chinese zodiac graphic elements. You can search on the Web for free
theme sets or image sets that contain banners, borders, background
images, buttons, icons, lines, and bullets designed around a specific
theme.
Create a Web banner image with a title of “The Chinese Zodiac” and
a subtitle of “A Code Demonstration for PHP”.
Save the banner image as ChineseZodiacBanner with an appropriate
graphic extension (.jpg, .gif, or .png) in an Images folder within the
ChineseZodiac folder and upload the document to the server.
Open the ChineseZodiacBanner image in both Internet Explorer and
Mozilla Firefox to determine if it displays well on the Web.
Discovery Project 1-2
Create nine buttons (approximately 150×30 pixels) with the follow-
ing face texts and filenames: “Home Page” = HomePage.img, “Site
Layout” = SiteLayout.img, “Control Structures” = ControlStructures.
img, “String Functions” = StringFunctions.img, “Web Forms” =
WebForms.img, “Midterm Assessment” = MidtermAssessment.
img, “State Information” = StateInformation.img, “User Templates” =
UserTemplates.img, and “Final Project” = FinalProject.img. Replace
.img with the appropriate extension for the image file type, such as
.jpg, .gif, or .png. Save the buttons in the Images folder within the
ChineseZodiac folder and upload the buttons to the server.

Discovery
Projects
Discovery
Project 1-3
Research
the Chinese zodiac and write a few paragraphs about it in
your
text editor to acquaint your audience with the concept of the
Chinese
horoscope and its origin. Cite your sources. Save the docu-
ment
as ChineseZodiac.txt in the ChineseZodiac folder and upload
the
document to the server.
73
Discovery
Project 1-4
Search
for free images (in any size) for each of the 12 signs of the
Chinese
zodiac. You will use these images in later projects. Try to
find
images that are similar in size, style, and form. Try to keep the
height
of the image between 50 and 100 pixels, and the width of the
image
between 50 and 150 pixels. Use the name of the sign as the
name
of the image file (as in Rooster.jpg or Pig.gif ). Save each of the
images
with an appropriate extension in the Images folder within the
ChineseZodiac
folder, and upload the images to the server.
CHAPTER
Functions
and
Control
Structures
In
this chapter, you will:
2
Study
how to use functions to organize your PHP code
Learn
about variable scope
Make
decisions using if, if . . . else, and switch
statements
Repeatedly
execute code using while, do . . . while,
for,
and foreach statements
Learn
about include and require statements
Working
with Functions
So
far, the code you have written has consisted of simple statements
placed
within script sections. However, almost all programming
languages,
including PHP, allow you to group programming state-
ments
into logical units. In PHP, groups of statements that you can
execute
as a single unit are called functions. You will learn how to
create
your own custom functions in this chapter. The code you have
written
so far has also been linear in nature. In other words, your
programs
start at the beginning and end when the last statement in
the
program executes. Decision-making and looping statements allow
you
to determine the order in which other statements execute in a
program.
Controlling the flow of code and making decisions during
program
execution are two of the most fundamental skills required in
programming.
In this chapter, you will learn about decision-making
statements
and flow-control statements.
75
Working
with Functions
In
Chapter 1, you learned that PHP includes numerous built-in func-
tions
that you can use in your scripts. Functions are useful because
they
make it possible to treat a related group of PHP statements as a
single
unit. In this section, you will learn how to write custom func-
tions.
Then, you will learn how to use these functions in your scripts.
Defining
Functions
Before
you can use a function in a PHP program, you must first cre-
ate,
or define, it. The lines of code that make up a function are called
the
function definition. The syntax for defining a function is as
follows:
<?php
function
name_of_function(parameters) {
statement(s);
}
?>
As shown in
the preced-