05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table 2-2. Escape sequences in double-quoted strings (continued)<br />

Escape sequence Character represented<br />

\r Carriage return<br />

\t Tab<br />

\\ Backslash<br />

\$ Dollar sign<br />

\{ Left brace<br />

\} Right brace<br />

\[ Left bracket<br />

\] Right bracket<br />

\0 through \777 ASCII character represented by octal value<br />

\x0 through \xFF ASCII character represented by hex value<br />

A single-quoted string only recognizes \\ to get a literal backslash and \' to get a literal<br />

single quote:<br />

$dos_path = 'C:\\WINDOWS\\SYSTEM';<br />

$publisher = 'Tim O\'Reilly';<br />

echo "$dos_path $publisher\n";<br />

C:\WINDOWS\SYSTEM Tim O'Reilly<br />

To test whether two strings are equal, use the == comparison operator:<br />

if ($a == $b) { echo "a and b are equal" }<br />

Use the is_string( ) function to test whether a value is a string:<br />

if (is_string($x)) {<br />

// $x is a string<br />

}<br />

<strong>PHP</strong> provides operators and functions to compare, disassemble, assemble, search,<br />

replace, and trim strings, as well as a host of specialized string functions for working<br />

with HTTP, HTML, and SQL encodings. Because there are so many string-manipulation<br />

functions, we’ve devoted a whole chapter (Chapter 4) to covering all the details.<br />

Booleans<br />

A boolean value represents a “truth value”—it says whether something is true or not.<br />

Like most programming languages, <strong>PHP</strong> defines some values as true and others as<br />

false. Truth and falseness determine the outcome of conditional code such as:<br />

if ($alive) { ... }<br />

In <strong>PHP</strong>, the following values are false:<br />

• The keyword false<br />

• The integer 0<br />

• The floating-point value 0.0<br />

26 | Chapter 2: Language Basics<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!