PHP.nl

htmlentities

htmlentities

Convert all applicable characters to HTML entities

string **htmlentities** string $string int $flags  $encoding bool $double_encode

This function is identical to in all ways, except with , all characters which have HTML character entity equivalents are translated into these entities. The function can be used to return the translation table used dependent upon the provided constants. htmlspecialchars``htmlentities``get_html_translation_table``flags

If you want to decode instead (the reverse) you can use . html_entity_decode

stringThe input string.

flags A bitmask of one or more of the following flags, which specify how to handle quotes, invalid code unit sequences and the used document type. The default is .

  `ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401`

encoding``double_encode When is turned off PHP will not encode existing html entities. The default is to convert everything. double_encode

Returns the encoded string.

If the input contains an invalid code unit sequence within the given an empty string will be returned, unless either the or flags are set. string``encoding``ENT_IGNORE``ENT_SUBSTITUTE

Voorbeeld: A example

<?php
$str = "A 'quote' is <b>bold</b>";

echo htmlentities($str);
echo "\n\n";
echo htmlentities($str, ENT_COMPAT);
?>
A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;

A 'quote' is &lt;b&gt;bold&lt;/b&gt

**Voorbeeld: Usage of **

<?php
$str = "\x8F!!!";

// Outputs an empty string
echo htmlentities($str, ENT_QUOTES, "UTF-8");

// Outputs "!!!"
echo htmlentities($str, ENT_QUOTES | ENT_IGNORE, "UTF-8");
?>

html_entity_decode``get_html_translation_table``htmlspecialchars``nl2br``urlencode