On Thu, 9 Oct 2003 11:53:51 +1000, you wrote: >Hi all, > >I'm interested in alternative solutions (to those found in the comments >on http://au.php.net/htmlspecialchars) for dealing with text pasted >into a textarea from Word et al. > >I want a way of 'dumbing down' certain characters (like quotes) before >putting them through my own smart quotes engine, and convert other >characters to their appropriate HTML entity. > >htmlspecialchars() doesn't seem to be converting a few test chars I >have (like curly quotes) > > >I'm interested in hearing of a few different methods to overcome the >evil MS Word text :)
/** * XML equivalent of htmlentities() - £ becomes £ * this function placed here to avoid calling in another include file **/ function xmlentities ($string, $quote_style = ENT_COMPAT) { static $trans; // using a static variable avoids repeatedly creating the translation table if (!is_array ($trans)) { $trans = get_html_translation_table (HTML_ENTITIES, $quote_style); $trans[chr(128)] = '€'; $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(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(159)] = 'Ÿ'; array_walk ($trans, create_function ('&$a, $b', '$a = "&#" . ord ($b) . ";";')); } return (strtr ($string, $trans)); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php