[Phpfreechat-svn] SF.net SVN: phpfreechat: [1143] trunk/src/pfctools.php
Status: Beta
Brought to you by:
kerphi
From: <gpi...@us...> - 2007-08-24 00:08:51
|
Revision: 1143 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1143&view=rev Author: gpinzone Date: 2007-08-23 17:08:49 -0700 (Thu, 23 Aug 2007) Log Message: ----------- Replaced the html_entity_decode for PHP <4.3.0 with the implementation from PHP_Compat. Modified Paths: -------------- trunk/src/pfctools.php Modified: trunk/src/pfctools.php =================================================================== --- trunk/src/pfctools.php 2007-08-23 21:02:56 UTC (rev 1142) +++ trunk/src/pfctools.php 2007-08-24 00:08:49 UTC (rev 1143) @@ -438,19 +438,52 @@ } /** - * html_entity_decode - * For users prior to PHP 4.3.0 + * Replace html_entity_decode() + * + * @category PHP + * @package PHP_Compat + * @link http://php.net/function.html_entity_decode + * @author David Irvine <da...@co...> + * @author Aidan Lister <ai...@ph...> + * @version $Revision: 1.8 $ + * @since PHP 4.3.0 + * @internal Setting the charset will not do anything + * @require PHP 4.0.0 (user_error) */ -if (!function_exists('html_entity_decode')) -{ - function html_entity_decode($string) + +if (!defined('ENT_NOQUOTES')) { + define('ENT_NOQUOTES', 0); +} + +if (!defined('ENT_COMPAT')) { + define('ENT_COMPAT', 2); +} + +if (!defined('ENT_QUOTES')) { + define('ENT_QUOTES', 3); +} + +if (!function_exists('html_entity_decode')) { + function html_entity_decode($string, $quote_style = ENT_COMPAT, $charset = null) { - // replace numeric entities - $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string); - $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string); - // replace literal entities + if (!is_int($quote_style)) { + user_error('html_entity_decode() expects parameter 2 to be long, ' . + gettype($quote_style) . ' given', E_USER_WARNING); + return; + } + $trans_tbl = get_html_translation_table(HTML_ENTITIES); $trans_tbl = array_flip($trans_tbl); + + // Add single quote to translation table; + $trans_tbl['''] = '\''; + + // Not translating double quotes + if ($quote_style & ENT_NOQUOTES) { + // Remove double quote from translation table + unset($trans_tbl['"']); + } + return strtr($string, $trans_tbl); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |