
- •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)
APPENDIX
B
of
the menu. The WampServer application closes and the icon is
removed
from the system tray.
Working
with the WampServer Menu
After
you install the WampServer, you can launch the application as
you
would any other Windows application. Click the Start button on
the
taskbar and select Programs | WampServer | Start WampServer.
The
WampServer icon appears in the system tray on the taskbar.
With
the application running, you can click the WampServer icon to
display
available menu options. If you click Apache or MySQL under the
Powered
by Anaska heading, you can verify that the service is running.
from
the submenu, you will see that the Stop Service option is active,
but
the Start/Resume Service option is grayed out (inactive). You can
use
the Stop Service option to stop the Web server while leaving other
services
available. Once the service is stopped, the Stop Service option is
grayed
out (inactive), but the Start/Resume Service option is active. You
can
then use the Start/Resume Service option to restart the Web server.
When
you finish using the WampServer, you can click the
WampServer
icon and select Stop All Services or right-click the icon
and
select Exit.
639
The
sameIf you select Apache from the WampServer menu and select Service
Stop Service
and Start/
Resume
Service
options are available for
all of the WampServer
services.
It is a good
idea to exit
the
WampServer
when you are
not developing Web
pages because it uses
computer resources and
memory.
Accessing WampServer Online
Typically, the local installation of WampServer is for development
purposes and the files are uploaded to a production server after they
have been tested. You probably do not want Web pages saved on your
local server to be globally accessible on the Web. For this reason, the
default option for accessibility is set to Put Offline.
To allow files saved in the root Web folder of your local computer to
be accessed outside your LAN:
1.
2.
You take
security
risks by
allowing
Internet
users to access your
local Web, PHP, and
MySQL servers. Use this
option with caution.
On your LAN gateway, enable port 80 for http in firewalls.
On your LAN gateway, forward port 80 for http to the
Internet Protocol (IP) address of the computer that has
WAMP installed.
From the WampServer menu, click Put Online.
Access your Web files by substituting “localhost” with your
Web IP address, which you can find at the Where is My IP
Web site (whereismyip.com) or by checking your gateway’s
configuration.
3.
4.
APPENDIX
B
Installing
the Directory Structure
for
Student Files
As
discussed in the preface, all of the files created and used for the
exercises,
Reinforcement Exercises, and Discovery Projects in this
book
conform to a standard directory layout. A .zip archive file that
contains
the layout and all the files needed to complete the exercises
is
available at the Cengage Web site (www.cengage.com). To install the
directories
and files, simply unzip the archive file in the Web folder
on
your local server (C:\wamp\www\ is the default for WAMP).
640
APPENDIX
Formatting
Strings
C
Using
the printf() and sprintf()
Functions
PHP
includes the printf()
and
sprintf()
functions,
which format
text
strings for output. The printf()
function
outputs a text string
directly,
similar to the print
and
echo
statements,
whereas the
sprintf()
function
formats a string and returns the formatted value
so
that you can assign it to a variable.
Both
functions accept as a first argument a format
control string,
which
contains instructions for formatting text strings. You surround
the
format control string with single or double quotation marks, the
same
as you do for other types of strings. Each function also accepts
additional
arguments containing the data to be formatted by the
format
control string. Within the format control string, you include
a
conversion specification for each of the data elements you want
to
format, along with any other text that you want to appear in the
formatted
string. A conversion
specification begins
with a percent
symbol
(%)
and specifies the formatting you want to apply to a data
element.
You must include a conversion specification for each argu-
ment
that is passed to the printf()
or
sprintf()
function
after the
format
control string. For example, the following code contains a
printf()
function
with two conversion specifications in the format
APPENDIX
C
control
string: one for the $FirstName
variable
and one for the
$SecondName
variable:
$FirstName
= "Gosselin";
$SecondName
= "Gauselin";
printf("<p>The
name %s is also spelled %s.</p>\n",
$FirstName,
$SecondName);
642
Notice that each conversion specification consists of a percent sym-
bol followed by the letter s. The letter following the percent symbol
in a conversion specification is a type specifier, which determines the
display format of each data argument that is passed to the printf()
or sprintf() function. A type specifier of s simply displays the data
argument as a standard string. The preceding example is equivalent to
the following code, which uses an echo statement.
$FirstName = "Gosselin";
$SecondName = "Gauselin";
echo "<p>The name $FirstName is also spelled $SecondName
</p>\n";
If you are only using a simple %s conversion specification, it will be
easier to use the standard PHP syntax instead. For more complex
formatting, the printf() and sprintf() functions provide options
that are not available in the standard PHP syntax. These options are
explained next.
Specifying Types
Table C-1 lists the type specifiers you can use with the printf() and
sprintf() functions.
Type
Specifier
b
c
d
u
f
o
s
x
X
Description
Displays the argument as a binary integer
Displays the ASCII character for the index specified by the argument
Displays the argument as a decimal integer
Displays the argument as an unsigned decimal integer
Displays the argument as a floating-point number
Displays the argument as an octal integer
Displays the argument as a string
Displays the argument as a lowercase hexadecimal integer
Displays the argument as an uppercase hexadecimal integer
PHP type specifiers
Table C-1

APPENDIX
C
The
following code demonstrates how to use each of the type speci-
fiers
listed in Table C-1. Figure C-1 shows the output.
$Value
= 163;
print("<p>\n
");
printf("Binary
integer: %b<br />\n ", $Value);
printf("ASCII
character: %c<br />\n ", $Value);
printf("Decimal
integer: %d<br />\n ", $Value);
printf("Unsigned
decimal integer: %u<br />\n ", $Value);
printf("Floating-point
number: %f<br />\n ", $Value);
printf("Octal
integer: %o<br />\n ", $Value);
printf("String:
%s<br />\n ", $Value);
printf("Lowercase
hexadecimal integer: %x<br />\n ", $Value);
printf("Uppercase
hexadecimal integer: %X<br />\n ", $Value);
print("</p>\n");
643
Figure
C-1
Using
the
sprintf() types
Determining Decimal Number Precision
A common use of the string formatting functions is to format num-
bers to be displayed with a specified number of decimal places. For
example, it’s often necessary to format numbers as currency, with two
decimal places. However, a variable that contains the currency value
you want to display might be an integer that does not contain decimal
places, or it might be a floating-point number that has more than
two decimal places. By default, the f type specifier formats numbers
with six decimal places. To specify a different number of decimal
places, add a period and an integer representing the desired number
of decimal places between the percent symbol and the f type speci-
fier in a conversion specification. In the following code, a value of
99.5 is assigned to the $RetailPrice variable. When the value in the
$RetailPrice variable is multiplied by 5% to add sales tax, the result-
ing value is 104.475, which is assigned to the $PriceWithTax variable.
The value is then formatted to two decimal places with the printf()
statement. Figure C-2 shows the output.
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.

APPENDIX
C
$RetailPrice
= 99.5;
$PriceWithTax
= $RetailPrice * 1.05;
printf("<p>The
retail price is $%.2f.</p>\n",
$RetailPrice);
printf("<p>The price with 5%% sales tax is $%.2f.</p>\n",
$PriceWithTax);
644
You can only
use a period
and number
of decimals
in a conver-
sion specification that
uses the f type specifier.
Figure C-2 Using the printf() statement
to format a number to two decimal places
Specifying Padding
In addition to specifying the number of decimal places that appear
to the right of a decimal point, you can specify the number of char-
acters used to output the data argument. For example, you might
have a variable that counts the number of visitors to your Web site.
Instead of just displaying the number of visitors, you might want to
format it to display the number of visitors out of a million by pad-
ding the beginning of the number with zeroes. To pad the beginning
of a string with zeroes, include a 0 and an integer representing the
number of characters the number should have between the percent
symbol and type specifier in a conversion specification. For example,
the conversion specification in the following sprintf() statement
specifies that the number should consist of seven characters. Because
the string representation of the $Visitors variable only contains four
characters, the beginning of the number is padded with three extra
zeroes, as shown in Figure C-3.
$DisplayValue = sprintf("%07d", 5767);
echo "<p>You are visitor number " .
$DisplayValue . ".</p>\n";
Use two per-
cent signs
(%%) to include
a percent
symbol as a
character in a format
control string.
Figure C-3
Padding a value with leading zeroes

APPENDIX
C
You
can also specify that a string should be padded with spaces
instead
of a 0. Simply use a space instead of the 0 or exclude the 0 in a
conversion
specification. However, most Web browsers automatically
replace
multiple spaces on a Web page with a single space, unless you
use
the <pre>
element.
If you want to pad a number with any charac-
ter
other than a 0 or a space, you must precede it with a single quo-
tation
mark (').
For example, the following code pads a string with
asterisks
(*) instead of spaces or zeroes. Figure C-4 shows the output.
$Payment
= 1410.23;
printf("<p>Pay
the amount of \$%’*9.2f.</p>\n", $Payment);
Padding
takes
into account
the number of
characters in
a string, not
the number of digits in an
integer. This includes the
decimal point and deci-
mal places. For example,
the number 345.10 con-
sists of six characters. If
you pad the formatting
string with zeroes and
specify that the format-
ting string should contain
eight characters, the
number will be formatted
as 00345.10.
If you add a
plus sign (+)
immediately
following the
percent sym-
bol in a conversion speci-
fication, positive numbers
are formatted with a plus
sign before them and
negative numbers are
formatted with a minus
sign (-) before them.
Otherwise, only negative
numbers will have a sign
preceding the value.
645
Figure C-4
Padding with asterisks
Formatting Numbers