note 42185 modified in function.html-entity-decode by tomsommer
| From: | tomsommer@php.net | Date: | Mon, 13 Sep 2004 22:01:38 +0000 |
| Subject: | note 42185 modified in function.html-entity-decode by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-76647@lists.php.net to get a copy of this message | ||
Well, I needed this at some stage, so it may be of some use to others with PHP<4.3.0. Here is a
working replica of html_entity_decode():
<?php
if (!function_exists('html_entity_decode')) {
function html_entity_decode ($string, $opt = ENT_COMPAT) {
$trans_tbl = get_html_translation_table (HTML_ENTITIES, $opt);
$trans_tbl = array_flip ($trans_tbl);
if ($opt & 1) { // Translating single quotes
// Add single quote to translation table;
// doesn't appear to be there by default
$trans_tbl["'"] = "'";
}
if (!($opt & 2)) { // Not translating double quotes
// Remove double quote from translation table
unset($trans_tbl["""]);
}
return strtr ($string, $trans_tbl);
}
}
// Just to be safe ;o)
if (!defined("ENT_COMPAT")) define("ENT_COMPAT", 2);
if (!defined("ENT_NOQUOTES")) define("ENT_NOQUOTES", 0);
if (!defined("ENT_QUOTES")) define("ENT_QUOTES", 3);
?>
--was--
Well, I needed this at some stage, so it may be of some use to others with PHP<4.3.0. Here is a
working replica of html_entity_decode():
<?php
if (!function_exists('html_entity_decode')) {
function html_entity_decode ($string, $opt = ENT_COMPAT) {
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
if ($opt & 1) { // Translating single quotes
// Add single quote to translation table;
// doesn't appear to be there by default
$trans_tbl["'"] = "'";
}
if (!($opt & 2)) { // Not translating double quotes
// Remove double quote from translation table
unset($trans_tbl["""]);
}
return strtr ($string, $trans_tbl);
}
}
// Just to be safe ;o)
if (!defined("ENT_COMPAT")) define("ENT_COMPAT", 2);
if (!defined("ENT_NOQUOTES")) define("ENT_NOQUOTES", 0);
if (!defined("ENT_QUOTES")) define("ENT_QUOTES", 3);
?>
http://php.net/manual/en/function.html-entity-decode.php