note 41733 deleted from function.htmlspecialchars by cmb

From: Date: Sun, 27 Oct 2019 09:17:39 +0000
Subject: note 41733 deleted from function.htmlspecialchars by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212850@lists.php.net to get a copy of this message
Note Submitter: moc.xnoitadnuof@310symerej ---- Here are some usefull functions. They will apply || decode, htmlspecialchars || htmlentities recursivly to arrays() || to regular $variables. They also protect agains "double encoding". <?PHP function htmlspecialchars_or( $mixed, $quote_style = ENT_QUOTES ){ return is_array($mixed) ? array_map('htmlspecialchars_or',$mixed, array_fill(0,count($mixed),$quote_style)) : htmlspecialchars(htmlspecialchars_decode($mixed, $quote_style ),$quote_style); } function htmlspecialchars_decode( $mixed, $quote_style = ENT_QUOTES ) { if(is_array($mixed)){ return array_map('htmlspecialchars_decode',$mixed, array_fill(0,count($mixed),$quote_style)); } $trans_table = get_html_translation_table( HTML_SPECIALCHARS, $quote_style ); if( $trans_table["'"] != '&#039;' ) { # some versions of PHP match single quotes to &#39; $trans_table["'"] = '&#039;'; } return (strtr($mixed, array_flip($trans_table))); } function htmlentities_or($mixed, $quote_style = ENT_QUOTES){ return is_array($mixed) ? array_map('htmlentities_or',$mixed, array_fill(0,count($mixed),$quote_style)) : htmlentities(htmlentities_decode($mixed, $quote_style ),$quote_style); } function htmlentities_decode( $mixed, $quote_style = ENT_QUOTES ) { if(is_array($mixed)){ return array_map('htmlentities_decode',$mixed, array_fill(0,count($mixed),$quote_style)); } $trans_table = get_html_translation_table(HTML_ENTITIES, $quote_style ); if( $trans_table["'"] != '&#039;' ) { # some versions of PHP match single quotes to &#39; $trans_table["'"] = '&#039;'; } return (strtr($mixed, array_flip($trans_table))); } ?> These functions are an addition to an earlier post. I would like to give the person some credit but I do not know who it was. <? ;llnu=u!eJq dHd?>

« previous php.notes (#212850) next »