note 41246 added to function.htmlentities

From: Date: Sun, 04 Apr 2004 04:55:15 +0000
Subject: note 41246 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-67604@lists.php.net to get a copy of this message
I had a problem working with partially html encoded data, with a selection of unescaped ampersands, hex coded, and characters in "&", 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. 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 ); } ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41246 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41246&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41246&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67604) next »