PHP html_entity_decode() Funzione
❮ Riferimento alla stringa PHP
Esempio
Converti entità HTML in caratteri:
<?php
$str = '<a href="https://www.w3schools.com">w3schools.com</a>';
echo html_entity_decode($str);
?>
L'output HTML del codice sopra sarà (Visualizza sorgente):
<a href="https://www.w3schools.com">w3schools.com</a>
L'output del browser del codice sopra sarà:
Definizione e utilizzo
La funzione html_entity_decode() converte le entità HTML in caratteri.
La funzione html_entity_decode() è l'opposto di htmlentities() .
Sintassi
html_entity_decode(string,flags,character-set)
Valori dei parametri
Parameter | Description |
---|---|
string | Required. Specifies the string to decode |
flags | Optional. Specifies how to handle quotes and which document type to use. The available quote styles are:
Additional flags for specifying the used doctype:
|
character-set | Optional. A string that specifies which character-set to use. Allowed values are:
Note: Unrecognized character-sets will be ignored and replaced by ISO-8859-1 in versions prior to PHP 5.4. As of PHP 5.4, it will be ignored an replaced by UTF-8. |
Dettagli tecnici
Valore di ritorno: | Restituisce la stringa convertita |
---|---|
Versione PHP: | 4.3.0+ |
Registro delle modifiche: | PHP 5.6 - Modificato il valore predefinito per il
parametro del set di caratteri nel valore del set di caratteri predefinito (nella configurazione). PHP 5.4 - Modificato il valore predefinito per il parametro del set di caratteri in UTF-8. PHP 5.4 - Aggiunti ENT_HTML401, ENT_HTML5, ENT_XML1 e ENT_XHTML. PHP 5.0 - Aggiunto supporto per codifiche multi-byte |
Altri esempi
Esempio
Converti alcune entità HTML in caratteri:
<?php
$str = "Albert Einstein said: 'E=MC²'";
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
?>
L'output HTML del codice sopra sarà (Visualizza sorgente):
Albert Einstein said: 'E=MC²'<br>
Albert Einstein said: 'E=MC²'<br>
Albert Einstein said: 'E=MC²'
L'output del browser del codice sopra sarà:
Albert Einstein said: 'E=MC²'
Albert Einstein said: 'E=MC²'
Albert
Einstein said: 'E=MC²'
Esempio
Converti alcune entità HTML in caratteri, utilizzando il set di caratteri dell'Europa occidentale:
<?php
$str = "My name is Øyvind Åsane. I'm Norwegian.";
echo html_entity_decode($str, ENT_QUOTES, "UTF-8");
?>
L'output HTML del codice sopra sarà (Visualizza sorgente):
My name is Øyvind Åsane. I'm Norwegian.
L'output del browser del codice sopra sarà:
My name is Øyvind Åsane. I'm Norwegian.
❮ Riferimento alla stringa PHP