note 41733 added to function.htmlspecialchars
| From: | moc dot xnoitadnuof at 310symerej dot php dot net | Date: | Wed, 21 Apr 2004 08:04:45 +0000 |
| Subject: | note 41733 added to function.htmlspecialchars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68412@lists.php.net to get a copy of this message | ||
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["'"] != ''' ) { # some versions of PHP match
single quotes to '
$trans_table["'"] = ''';
}
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["'"] != ''' ) { # some versions of PHP match
single quotes to '
$trans_table["'"] = ''';
}
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?>
----
Manual Page -- http://www.php.net/manual/en/function.htmlspecialchars.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41733
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41733&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41733&report=yes
Search -- http://master.php.net/manage/user-notes.php