Función PHP html_entity_decode()
❮ Referencia de cadenas de PHP
Ejemplo
Convierta entidades HTML en caracteres:
<?php
$str = '<a href="https://www.w3schools.com">w3schools.com</a>';
echo html_entity_decode($str);
?>
La salida HTML del código anterior será (Ver código fuente):
<a href="https://www.w3schools.com">w3schools.com</a>
La salida del navegador del código anterior será:
Definición y uso
La función html_entity_decode() convierte entidades HTML en caracteres.
La función html_entity_decode() es lo opuesto a htmlentities() .
Sintaxis
html_entity_decode(string,flags,character-set)
Valores paramétricos
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. |
Detalles técnicos
Valor devuelto: | Devuelve la cadena convertida |
---|---|
Versión PHP: | 4.3.0+ |
Registro de cambios: | PHP 5.6: cambió el valor predeterminado para el parámetro del juego de caracteres
al valor del juego de caracteres predeterminado (en configuración). PHP 5.4: se cambió el valor predeterminado para el parámetro de conjunto de caracteres a UTF-8. PHP 5.4: se agregaron ENT_HTML401, ENT_HTML5, ENT_XML1 y ENT_XHTML. PHP 5.0: soporte agregado para codificaciones de varios bytes |
Más ejemplos
Ejemplo
Convierta algunas entidades HTML en caracteres:
<?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
?>
La salida HTML del código anterior será (Ver código fuente):
Albert Einstein said: 'E=MC²'<br>
Albert Einstein said: 'E=MC²'<br>
Albert Einstein said: 'E=MC²'
La salida del navegador del código anterior será:
Albert Einstein said: 'E=MC²'
Albert Einstein said: 'E=MC²'
Albert
Einstein said: 'E=MC²'
Ejemplo
Convierta algunas entidades HTML en caracteres, utilizando el conjunto de caracteres de Europa occidental:
<?php
$str = "My name is Øyvind Åsane. I'm Norwegian.";
echo html_entity_decode($str, ENT_QUOTES, "UTF-8");
?>
La salida HTML del código anterior será (Ver código fuente):
My name is Øyvind Åsane. I'm Norwegian.
La salida del navegador del código anterior será:
My name is Øyvind Åsane. I'm Norwegian.
❮ Referencia de cadenas de PHP