Mostrar lista de opciones

htmlspecialchars()

« htmlentities | htmlspecialchars_decode »
<?php
$string 
htmlspecialchars (
    
// string $string
    
?// [int $flags = ENT_COMPAT | ENT_HTML401]
    
?// [string $encoding = 'UTF-8']
    
?  // [bool $double_encode = true]
);

// enter non ASCII characters in hex in $string if $encoding is not UTF-8
// the returned $string may not display properly if $encoding is not UTF-8

// shows the returned $string in UTF-8 if $encoding is not UTF-8
// note that $encoding below actually represents an argument
if ($encoding and $encoding != "UTF-8")
    
$utf8 mb_convert_encoding($string"UTF-8"$encoding);
?>
Resultado
$string = '&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;'
Ejemplos
#1 htmlspecialchars  ("<a href='test'>Test</a>",
 
ENT_QUOTES)
#2 htmlspecialchars  ("'à' is not 'a'",
 
ENT_QUOTES)
#3 htmlspecialchars  ("'\xe0' is not 'a'",
 
ENT_QUOTES,
 
"ISO-8859-1")
Ver también
get_html_translation_table, html_entity_decode, htmlentities, htmlspecialchars_decode, nl2br, strip_tags