PHP htmlspecialchars_decode() Funzione
❮ Riferimento alla stringa PHP
Esempio
Converti le entità HTML predefinite "<" (minore di) e ">" (maggiore di) ai caratteri:
<?php
$str = "This is some <b>bold</b> text.";
echo htmlspecialchars_decode($str);
?>
L'output HTML del codice sopra sarà (Visualizza sorgente):
<!DOCTYPE html>
<html>
<body>
This is some <b>bold</b> text.
</body>
</html>
L'output del browser del codice sopra sarà:
This is some bold text.
Definizione e utilizzo
La funzione htmlspecialchars_decode() converte alcune entità HTML predefinite in caratteri.
Le entità HTML che verranno decodificate sono:
- & diventa & (e commerciale)
- " diventa " (virgolette doppie)
- ' diventa ' (virgoletta singola)
- < diventa < (minore di)
- > diventa > (maggiore di)
La funzione htmlspecialchars_decode() è l'opposto di htmlspecialchars() .
Sintassi
htmlspecialchars_decode(string,flags)
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:
|
Dettagli tecnici
Valore di ritorno: | Restituisce la stringa convertita |
---|---|
Versione PHP: | 5.1.0+ |
Registro delle modifiche: | PHP 5.4 - Aggiunti ENT_HTML401, ENT_HTML5, ENT_XML1 e ENT_XHTML. |
Altri esempi
Esempio
Converti alcune entità HTML predefinite in caratteri:
<?php
$str = "Jane & 'Tarzan'";
echo htmlspecialchars_decode($str, ENT_COMPAT); // Will only convert double quotes
echo "<br>";
echo htmlspecialchars_decode($str, ENT_QUOTES); // Converts double and single quotes
echo "<br>";
echo htmlspecialchars_decode($str, ENT_NOQUOTES); // Does not convert any quotes
?>
L'output HTML del codice sopra sarà (Visualizza sorgente):
<!DOCTYPE html>
<html>
<body>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'
</body>
</html>
L'output del browser del codice sopra sarà:
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
Esempio
Converti le entità HTML predefinite in virgolette doppie:
<?php
$str = 'I love "PHP".';
echo htmlspecialchars_decode($str, ENT_QUOTES); // Converts double and single quotes
?>
L'output HTML del codice sopra sarà (Visualizza sorgente):
<!DOCTYPE html>
<html>
<body>
I love "PHP".
</body>
</html>
L'output del browser del codice sopra sarà:
I love "PHP".
❮ Riferimento alla stringa PHP