PHP » Strings » htmlentities()

Syntax:
string htmlentities(string s [, int quote_style [, string characterset]])
s
String .
quote_style
How to encode quotes.
characterset
Character set to use.

Converts characters to html entities.

Characters that may not be displayed correctly in the character set used, should be encoded as html entities. htmlentities() replaces such characters in a string with their corresponding html entities. A new translated string is returned. The quote_style parameter specifies whether quotes should be escaped. The possible values for quote_style are ENT_COMPAT, which only escapes double quotes, ENT_NOQUOTES, for no quote escaping, and ENT_QUOTES for escaping both double and single quotes. The characterset parameter specifies a character set to use for the translation. Default is ISO-8859-1.

Examples

Code:
<?php

$s = '"Foreign" letters often cause trouble: éèôåäö';
print htmlspecialchars(htmlentities($s, ENT_NOQUOTES), ENT_NOQUOTES);

?>
Output:
"Foreign" letters often cause trouble: &eacute;&egrave;&ocirc;&aring;&auml;&ouml;
Explanation:

A number of non-English characters are converted to their corresponding html entities. htmlspecialchars() is used on the result so that the contents of the string may be examined.

See Also: