htmlspecialchars
htmlspecialchars
Convert special characters to HTML entities
string **htmlspecialchars** string $string int $flags $encoding bool $double_encode
Certain characters have special significance in HTML, and should
be represented by HTML entities if they are to preserve their
meanings. This function returns a string with these
conversions made. If you require all input substrings that have associated
named entities to be translated, use
instead.
htmlentities
If the input string passed to this function and the final document share the
same character set, this function is sufficient to prepare input for
inclusion in most contexts of an HTML document. If, however, the input can
represent characters that are not coded in the final document character set
and you wish to retain those characters (as numeric or named entities),
both this function and (which only encodes
substrings that have named entity equivalents) may be insufficient.
You may have to use instead.
htmlentities``mb_encode_numericentity
string
The being converted.
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
For the purposes of this function, the encodings
, ,
, ,
, , and
are effectively equivalent, provided the
itself is valid for the encoding, as
the characters affected by occupy
the same positions in all of these encodings.
ISO-8859-1``ISO-8859-15``UTF-8``cp866``cp1251``cp1252``KOI8-R``string``htmlspecialchars
double_encode
When is turned off PHP will not
encode existing html entities, the default is to convert everything.
double_encode
The converted .
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: example
<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // <a href='test'>Test</a>
?>
Opmerking: > Note that this function does not translate anything beyond what is listed above. For full entity translation, see .
htmlentities
Opmerking: > In case of an ambiguous value, the following rules apply:
flags
- When neither of , , is present, the default is .
ENT_COMPAT``ENT_QUOTES``ENT_NOQUOTES``ENT_NOQUOTES- When more than one of , , is present, takes the highest precedence, followed by .
ENT_COMPAT``ENT_QUOTES``ENT_NOQUOTES``ENT_QUOTES``ENT_COMPAT- When neither of , , , is present, the default is .
ENT_HTML401``ENT_HTML5``ENT_XHTML``ENT_XML1``ENT_HTML401- When more than one of , , , is present, takes the highest precedence, followed by , and .
ENT_HTML401``ENT_HTML5``ENT_XHTML``ENT_XML1``ENT_HTML5``ENT_XHTML``ENT_XML1``ENT_HTML401- When more than one of , , are present, takes the highest precedence, followed by .
ENT_DISALLOWED``ENT_IGNORE``ENT_SUBSTITUTE``ENT_IGNORE``ENT_SUBSTITUTE
get_html_translation_table``htmlspecialchars_decode``strip_tags``htmlentities``nl2br