Adding charset/encoding settings to h(), closes #4040

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6541 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-03-09 21:41:13 +00:00
parent 98831d27fe
commit c40bead47c

View file

@ -274,13 +274,20 @@ if (!function_exists('clone')) {
* Convenience method for htmlspecialchars. * Convenience method for htmlspecialchars.
* *
* @param string $text Text to wrap through htmlspecialchars * @param string $text Text to wrap through htmlspecialchars
* @param string $charset Character set to use when escaping. Defaults to config value in 'App.encoding' or 'UTF-8'
* @return string Wrapped text * @return string Wrapped text
*/ */
function h($text) { function h($text, $charset = null) {
if (is_array($text)) { if (is_array($text)) {
return array_map('h', $text); return array_map('h', $text);
} }
return htmlspecialchars($text); if (empty($charset)) {
$charset = Configure::read('App.encoding');
}
if (empty($charset)) {
$charset = 'UTF-8';
}
return htmlspecialchars($text, ENT_QUOTES, $charset);
} }
/** /**
* Returns an array of all the given parameters. * Returns an array of all the given parameters.