To facilitate such shortcomings, a set of universal
key codes was devised, known as character entity references. When these entities are
parsed by the browser, they will be converted into their recognizable counterparts.
For example, the three aforementioned characters would be presented as ©,
¢, and È, respectively.
To perform these conversions, you can use the htmlentities() function. Its prototype
follows:
string htmlentities(string str [, int quote_style [, int charset]])
Because of the special nature of quote marks within markup, the optional quote_style
parameter offers the opportunity to choose how they will be handled. Three values
are accepted:
ENT_COMPAT: Convert double quotes and ignore single quotes. This is the default.
ENT_NOQUOTES: Ignore both double and single quotes.
ENT_QUOTES: Convert both double and single quotes.
256 CHAPTER 9 ?– STRINGS AND REGULAR EXPRESSIONS
A second optional parameter, charset, determines the character set used for the
conversion. Table 9-2 offers the list of supported character sets. If charset is omitted,
it will default to ISO-8859-1.
The following example converts the necessary characters for Web display:
$advertisement = "Coffee at 'Caf?? Fran?§aise' costs $2.25.";
echo htmlentities($advertisement);
?>
This returns the following:
Coffee at 'Cafè Française' costs $2.25.
Two characters are converted, the grave accent (??) and the cedilla (?§).
Pages:
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333