Page 106 - Open Soource Technologies 304.indd
P. 106
Web Technologies-I
Notes Table 5.1: Escape Sequences in Double-quoted Strings
Escape sequence Character represented
\” Double quotes
\n Newline
\r Carriage return
\t Tab
\\ Backslash
\$ Dollar sign
\{ Left brace
\} Right brace
\[ Left bracket
\] Right bracket
\0 through \777 ASCII character represented by octal value
\x0 through \xFF ASCII character represented by hex value
If an unknown escape sequence (i.e. a backslash followed by a character that is not one of those
in Table 5.1) is found in a double-quoted string literal, it is ignored (if you have the warning level
E_NOTICE set, a warning is generated for such unknown escape sequences):
$str = “How are \c you?” // unknown escape sequence echo $str ; How are \c you?
String functions do not handle multibyte encodings such as UTF-8. We use
the functions found in multibyte string for encodings.
Self Assessment
True or False:
1. The string in PHP is implemented as an array of bytes and an integer indicating the length
of the buffer.
(a) True (b) False
2. The process of replacing variable names in the string with the values of those variables is
called interpolation.
(a) True (b) False
3. Single-quoted strings do not interpolate variables.
(a) True (b) False
5.2 Printing Strings
There are four ways to send output to the browser. The echo construct lets you print many values
at once, while print ( ) prints only one value. The printf( ) function builds a formatted string by
inserting values into a template. The print_r( ) function is useful for debugging it prints the contents
of arrays, objects, and other things, in a more or less human-readable form.
100 LOVELY PROFESSIONAL UNIVERSITY