
- •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)
CHAPTER
3
Manipulating
Strings
126
When
you want to include single quotes within a literal string, the
easiest
method is to surround the literal string with double quotation
marks.
Likewise, to include double quotes within a literal string, you
can
surround the string with single quotation marks. For example, the
following
statement assigns a text string surrounded by double quota-
tion
marks to the $LatinQuote
variable.
Figure 3-2 shows the output
of
the echo
statement.
$LatinQuote
= '<p>"Et tu, Brute!"</p>';
echo
$LatinQuote;
Figure
3-2
Displaying
a string that contains double quotation marks
Later
in this chapter, you will learn other methods to include quota-
tion
marks and other special characters in text strings.
Working
with String Operators
Up
to this point, you have displayed values from multiple literal
strings
and variables by passing them to the echo
and
print
state-
ments
as multiple arguments separated by commas. For example, the
following
code passes two literal strings and a variable to the echo
statement:
$Speaker
= "Julius Caesar";
echo
'<p>"Et tu, Brute!", exclaimed ', $Speaker, ".</p>";
of
these operators is the concatenation
operator (.).
The following
code
uses the concatenation operator to combine several string vari-
ables
and literal strings, and assigns the new value to another variable:
$City
= "Paris";
$Country
= "France";
$Destination
= "<p>" . $City . " is in "
.
$Country . ".</p>";In php, you can also use two operators to combine strings. The first
echo $Destination;
Constructing
Text Strings
The
combined value of the $City
and
$Country
variables
and the
literal
strings that are assigned to the $Destination
variable
is
<p>Paris
is in France.</p>.
You
can also combine strings using the concatenation
assignment
operator
(.=).
The following code combines two text strings, but
without
using the $City
or
$Country
variables:
$Destination
= "<p>Paris";
$Destination
.= " is in France.</p>";
echo
$Destination;
127
Again,
the value of the $Destination
variable
is "<p>Paris
is in
France.</p>".
To
build a string using the concatenation assignment operator:
1.
2.
Create
a new document in your text editor.
Type
the <!DOCTYPE>
declaration,
<html>
element,
document
head,
and <body>
element.
Use the strict DTD and “Musical
Scale”
as the content of the <title>
element.
Add
the following script section to the document body:
<?php
?>
3.
4.
Insert
the following array in the script section:
$MusicalScale
= array("do", "re", "mi", "fa",
"so",
"la",
"ti");
5.
Build
an output string using a foreach
loop
with the
$MusicalNotes
array,
as follows:
$OutputString="The
notes of the musical scale are: ";
foreach
($MusicalScale as $CurrentNote)
$OutputString
.= " " . $CurrentNote;
6.
Add the following statements to display the results in your
browser window.
echo "<p>$OutputString</p>";
7.
Save the file as MusicalScale.php, upload it to the Chap-
ter folder for Chapter 3, and then open the file in your Web
browser by entering the following URL:
http://<yourserver>/PHP_Projects/Chapter.03/Chapter/
MusicalScale.php. Figure 3-3 shows the output.

CHAPTER
3
Manipulating
Strings
128
Figure
3-3
Output
of MusicalScale.php
8.
Close
your Web browser window.
Adding
Escape Characters and Sequences
You
need to take extra care when using single quotation marks with
possessives
and contractions in strings surrounded by single quota-
tion
marks because the PHP scripting engine always looks for the first
closing
single quotation mark to match an opening single quotation
mark.
For example, consider the following statement:
echo
'<p>This code's not going to work.</p>';
This
statement displays incorrectly because the PHP scripting engine
assumes
that the literal string ends with the apostrophe following “code.”
To
get around this problem, you should include an escape character
before
the apostrophe in “code’s”. An escape
character tells
the compiler
or
interpreter that the character that follows it has a special
purpose.
In
PHP, the escape character is the backslash (\).
Placing a backslash in
front
of an apostrophe tells the PHP scripting engine to treat the apos-
trophe
as a regular keyboard character, such as “a,” “b,” “1,”
or “2,” and not
as
part of a single quotation mark pair that encloses a text string.
The
backslash
in the following statement tells the PHP scripting engine to
display
the apostrophe following the word “code” as an apostrophe:
echo
'<p>This code\'s going to work.</p>';
There’s
no need for a backslash before an apostrophe if you surround
the
text string with double quotation marks, as follows:
echo
"<p>This code's going to work.</p>";
Although
the apostrophe in the preceding statement displays cor-
rectly,
other characters require an escape character within a string
surrounded
by double quotation marks. The escape character
combined
with one or more other characters is called an escape
sequence.
The backslash followed by an apostrophe (\')
is an exam-
ple
of an escape sequence. Most escape sequences carry out special
functions;
for example, the escape sequence \t
inserts
a tab into a
string.
Table 3-1 describes the escape sequences that can be added to
a
double-quoted string in PHP.
Constructing
Text Strings
Escape
Sequence
\\
\$
\r
\f
\"
\t
\v
\n
\xh
\o
Within
a
literal string
surrounded
by double
quotation
marks, the backslash will
be displayed if you place
it before any character
other than those listed in
Table 3-1.
Description
Inserts a backslash
Inserts a dollar sign
Inserts a carriage return
Inserts a form feed
Inserts a double quotation mark
Inserts a horizontal tab
Inserts a vertical tab
Inserts a new line
Inserts a character whose hexadecimal value is h, where h is
one or two hexadecimal digits (0-9, A-F), case insensitive
Inserts a character whose octal value is o, where o is one,
two, or three octal digits (0-7)
PHP escape sequences within double quotation marks
129
Table 3-1
Notice that the backslash is one of the characters inserted into a
string by an escape sequence. Because the escape character itself
is a backslash, you must use the escape sequence \\ to include a
backslash as a character in a string. For example, to include the path
“C:\Course Technology\1687-5\” in a string, you must include a
backslash escape character before every literal backslash you want
to appear in the string, making each single backslash into a pair of
backslashes:
echo "<p>My PHP files are located in
C:\\Course Technology\\1687-5\\.</p>";
As a good
programming
practice, you
should include
an \n escape
sequence at the end of
an echo statement out-
put string as needed to
properly format the