function _link_html_entity_decode in Link 6.2
Wrapper around html_entity_decode to handle problems with PHP 4.
See http://drupal.org/node/739650 See http://bugs.php.net/bug.php?id=25670
We've taken this away from the beginning of file define() step, as this is going to be slower for PHP4, and we don't want to run this on every page load, just when we're doing a validate.
1 call to _link_html_entity_decode()
- link_validate_url in ./
link.inc - A lenient verification for URLs. Accepts all URLs following RFC 1738 standard for URL formation and all email addresses following the RFC 2368 standard for mailto address formation.
File
- ./
link.inc, line 262 - Helper functions for Link field, widget and form elements.
Code
function _link_html_entity_decode($html_string, $quote_style = ENT_COMPAT, $charset) {
if (defined('PHP_VERSION')) {
$version = explode('.', PHP_VERSION);
if ($version[0] == '5') {
return html_entity_decode($html_string, $quote_style, $charset);
// PHP 5, use default.
}
}
else {
$version = explode('.', PHP_VERSION);
if ($version[0] == '5') {
return html_entity_decode($html_string, $quote_style, $charset);
}
}
// use suggested code from http://drupal.org/node/739650
// replace numeric entities
$string = preg_replace('~&#x([0-9a-f]+);~ei', "_link_code2utf(hexdec('\\1'))", $html_string);
$string = preg_replace('~&#([0-9]+);~e', '_link_code2utf("\\1")', $string);
// replace literal entities.
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}