fix mb_str_replace to work with utf8

This commit is contained in:
monte.ohrt
2011-01-03 23:19:22 +00:00
parent 9630a99a82
commit d0b232e264
4 changed files with 44 additions and 49 deletions

View File

@@ -22,25 +22,6 @@
*/
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_RESOURCE_CHAR_SET)
{
if (!function_exists('mb_str_replace')) {
// simulate the missing PHP mb_str_replace function
function mb_str_replace($needles, $replacements, $haystack)
{
$rep = (array)$replacements;
foreach ((array)$needles as $key => $needle) {
$replacement = $rep[$key];
$needle_len = mb_strlen($needle);
$replacement_len = mb_strlen($replacement);
$pos = mb_strpos($haystack, $needle, 0);
while ($pos !== false) {
$haystack = mb_substr($haystack, 0, $pos) . $replacement
. mb_substr($haystack, $pos + $needle_len);
$pos = mb_strpos($haystack, $needle, $pos + $replacement_len);
}
}
return $haystack;
}
}
switch ($esc_type) {
case 'html':
return htmlspecialchars($string, ENT_QUOTES, $char_set);
@@ -85,12 +66,8 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_
return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', '</' => '<\/'));
case 'mail':
// safe way to display e-mail address on a web page
if (function_exists('mb_substr')) {
return mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
} else {
return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
}
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
case 'nonstd':
// escape non-standard chars, such as ms document quotes