função PHP html_entity_decode ()
Exemplos
O HTML em entidades de caracteres:
<?php
$str = "<© W3CSçh°°¦§>";
echo html_entity_decode($str);
?>
$str = "<© W3CSçh°°¦§>";
echo html_entity_decode($str);
?>
saída HTML do código acima é a seguinte (ver fonte):
<!DOCTYPE html>
<html>
<body>
<© W3CSch°°¦§>
</body>
</html>
<html>
<body>
<© W3CSch°°¦§>
</body>
</html>
saída do navegador de código acima é a seguinte:
<© W3CSch°°¦§>
Definição e Uso
html_entity_decode () para entidades HTML para caracteres.
função html_entity_decode () é o htmlentities () função inversa da função.
gramática
html_entity_decode( string,flags,character-se t)
参数 | 描述 |
---|---|
string | 必需。规定要解码的字符串。 |
flags | 可选。规定如何处理引号以及使用哪种文档类型。 可用的引号类型:
规定使用的文档类型的附加 flags:
|
character-set | 可选。一个规定了要使用的字符集的字符串。 允许的值:
注释:在 PHP 5.4 之前的版本,无法被识别的字符集将被忽略并由 ISO-8859-1 替代。自 PHP 5.4 起,无法被识别的字符集将被忽略并由 UTF-8 替代。 |
detalhes técnicos
retorna: | Retorna a string convertida. |
---|---|
versão do PHP: | 4.3.0+ |
log Update: | No PHP 5, parâmetros para UTF-8 valores padrão character-set. No PHP 5.4, adicione a exigência de utilização de sinalizadores adicionais para o tipo de documento: ENT_HTML401, ENT_HTML5, ENT_XML1 e ENT_XHTML. No PHP 5.0, adicionar suporte para codificações multi-byte. |
mais exemplos
exemplo 1
Alguns HTML em entidades de caracteres:
<?php
$str = "Jane & 'Tarzan'";
echo html_entity_decode($str, ENT_COMPAT); // Will only convert double quotes
echo "<br>";
echo html_entity_decode($str, ENT_QUOTES); // Converts double and single quotes
echo "<br>";
echo html_entity_decode($str, ENT_NOQUOTES); // Does not convert any quotes
?>
$str = "Jane & 'Tarzan'";
echo html_entity_decode($str, ENT_COMPAT); // Will only convert double quotes
echo "<br>";
echo html_entity_decode($str, ENT_QUOTES); // Converts double and single quotes
echo "<br>";
echo html_entity_decode($str, ENT_NOQUOTES); // Does not convert any quotes
?>
saída HTML do código acima é a seguinte (ver fonte):
<!DOCTYPE html>
<html>
<body>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'
</body>
</html>
<html>
<body>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'
</body>
</html>
saída do navegador de código acima é a seguinte:
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
exemplo 2
Ao utilizar os conjuntos de caracteres da Europa Ocidental, alguns HTML em entidades de caracteres:
<?php
$str = "My name is Øyvind Åsane. I'm Norwegian.";
echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1");
?>
$str = "My name is Øyvind Åsane. I'm Norwegian.";
echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1");
?>
A saída HTML do código acima será (View Source):
<!DOCTYPE html>
<html>
<body>
My name is Øyvind Åsane. I'm Norwegian.
</body>
</html>
<html>
<body>
My name is Øyvind Åsane. I'm Norwegian.
</body>
</html>
saída do navegador de código acima é a seguinte:
My name is Øyvind Åsane. I'm Norwegian.
PHP seqüência de referência