html_entity_decode

html_entity_decode -- Converte todas as entidades HTML para os seus caracteres

Descrição

string html_entity_decode ( string string [, int quote_style [, string charset]])

html_entity_decode( ) é o oposto da função htmlentities( ) no que converte todas as entidades HTML para os seus caracteres de string .

O segundo parâmetro , que é opcional , quote_style permite você definir o que será feito com ' apostrofos ' e "aspas " . Ele recebe uma constante entre três , sendo o padrão ENT_COMPAT :

Tabela 1 . Constantes disponíveis para quote_style

Nome da Constante Descrição
Irá converter aspas e deixar os apostrofos .
Irá converter ambos .
Irá deixar ambos sem converter .


O conjunto de caracteres ISO-8859-1 é usado como padrão para o terceiro parâmetro , que é opcional , charset . Este defini o conjunto de caracteres usado na conversão .

Exemplo 1 . Decodificando entidades html

 
?php

 
$orig

 
=

 
"

 
I'll

 
\"walk\

 
"

 
the

 
b

 
dog

 
/

 
b

 
now"

 
;

 
$a

 
=

 
htmlentities($orig)

 
;

 
$b

 
=

 
html_entity_decode($a)

 
;

 
echo

 
$a

 
;

 
/

 
/

 
I'll

 
quot;walk

 
quot

 
;

 
the

 
lt;b

 
gt;dog

 
lt

 
;

 
/

 
b

 
gt

 
;

 
now

 
echo

 
$b

 
;

 
/

 
/

 
I'll

 
"walk

 
"

 
the

 
b

 
dog

 
/

 
b

 
now

 
/

 
/

 
Para

 
versões

 
anteriores

 
ao

 
PHP

 
4.3.0

 
você

 
deve

 
fazer

 
isto

 
:

 
function

 
unhtmlentities

 
($string

 
)

 
{

 
$trans_tbl

 
=

 
get_html_translation_table

 
(HTML_ENTITIES)

 
;

 
$trans_tbl

 
=

 
array_flip

 
($trans_tbl)

 
;

 
return

 
strtr

 
($string

 
,

 
$trans_tbl)

 
;

 
}

 
$c

 
=

 
unhtmlentities($a)

 
;

 
echo

 
$c

 
;

 
/

 
/

 
I'll

 
"walk

 
"

 
the

 
b

 
dog

 
/

 
b

 
now

 

?





Veja também htmlentities( ) , htmlspecialchars( ) , get_html_translation_table( ) , htmlspecialchars( ) e urldecode( ) .