note 56150 deleted from function.htmlentities by mazzanet

From: Date: Mon, 03 Oct 2005 09:01:14 +0000
Subject: note 56150 deleted from function.htmlentities by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96245@lists.php.net to get a copy of this message
Note Submitter: ---- Regarding the post made by tmp1000 I have made modifications that will blank out all characters that are in Windows-1252 and not in ISO 8859-1. My problem was when pulling xml data from a database that users had submitted the text. The xml parser would fail on these particular characters and this function will fix that problem. function xmlentities($string, $quote_style=ENT_QUOTES) { static $trans; if (!isset($trans)) { $trans = get_html_translation_table(HTML_ENTITIES, $quote_style); foreach ($trans as $key => $value) $trans[$key] = '&#'.ord($key).';'; // dont translate the '&' in case it is part of &xxx; $trans[chr(38)] = '&'; // the following are all the invalid characters from Windows-1252 to ISO-8859-1 $trans[chr(9)] = ''; $trans[chr(10)] = ''; $trans[chr(11)] = ''; $trans[chr(12)] = ''; $trans[chr(130)] = ''; $trans[chr(131)] = ''; $trans[chr(132)] = ''; $trans[chr(133)] = ''; $trans[chr(134)] = ''; $trans[chr(135)] = ''; $trans[chr(136)] = ''; $trans[chr(137)] = ''; $trans[chr(138)] = ''; $trans[chr(139)] = ''; $trans[chr(140)] = ''; $trans[chr(141)] = ''; $trans[chr(142)] = ''; $trans[chr(143)] = ''; $trans[chr(144)] = ''; $trans[chr(145)] = ''; $trans[chr(146)] = ''; $trans[chr(147)] = ''; $trans[chr(148)] = ''; $trans[chr(149)] = ''; $trans[chr(150)] = ''; $trans[chr(151)] = ''; $trans[chr(152)] = ''; $trans[chr(153)] = ''; $trans[chr(154)] = ''; $trans[chr(155)] = ''; $trans[chr(156)] = ''; $trans[chr(157)] = ''; $trans[chr(158)] = ''; $trans[chr(159)] = ''; } // after the initial translation, _do_ map standalone '&' into '&' return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" , strtr($string, $trans)); }

« previous php.notes (#96245) next »