note 41246 deleted from function.htmlentities by hholzgra

From: Date: Thu, 02 Aug 2012 11:22:38 +0000
Subject: note 41246 deleted from function.htmlentities by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189583@lists.php.net to get a copy of this message
Note Submitter: Funky Ants ---- I had a problem working with partially html encoded data, with a selection of unescaped ampersands, hex coded, and characters in "&amp;", style. Which ive finally overcome by decoding all of the data, adn then reincoding it all. I found a combination of a couple of peoples work useful. <?php function get_htmlspecialchars( $given, $quote_style = ENT_QUOTES ){ return htmlentities( unhtmlentities( $given ) , $quote_style ); } function unhtmlentities( $string ){ $trans_tbl = get_html_translation_table ( HTML_ENTITIES ); $trans_tbl = array_flip( $trans_tbl ); $ret = strtr( $string, $trans_tbl ); return preg_replace( '/&#(\d+);/me' , "chr('\\1')" , $ret ); } ?>

« previous php.notes (#189583) next »