Specifications
The first column shows the function name, the second describes its effect, the third shows how
it would be applied to the string $subject, and the last column shows what value would be
returned from the function.
TABLE 4.2 String Case Functions and Their Effects
Function Description Use Value
$subject Feedback from
web site
strtoupper() Turns string to strtoupper($subject) FEEDBACK FROM
uppercase WEB SITE
strtolower() Turns string to strtolower($subject) feedback from
lowercase web site
ucfirst() Capitalizes first ucfirst($subject) Feedback from
character of string web site
if it’s alphabetic
ucwords() Capitalizes first ucwords($subject) Feedback From
character of each Web Site
word in the string
that begins with
an alphabetic
character.
Formatting Strings for Storage: AddSlashes() and
StripSlashes()
As well as using string functions to reformat a string visually, we can use some of these func-
tions to reformat strings for storage in a database. Although we won’t cover actually writing to
the database until Part II, “Using MySQL,” we will cover formatting strings for database stor-
age now.
Certain characters are perfectly valid as part of a string but can cause problems, particularly
when inserting data into a database because the database could interpret these characters as
control characters. The problematic ones are quotes (single and double), backslashes (\), and
the NUL character.
We need to find a way of marking, or escaping, these characters so that databases such as
MySQL can understand that we meant a literal special character rather than a control sequence.
To escape these characters, add a backslash in front of them. For example, “ (double quote)
becomes \” (backslash double quote), and \ (backslash) becomes \\ (backslash backslash).
Using PHP
P
ART I
100
06 7842 CH04 3/6/01 3:41 PM Page 100