mirror of
https://github.com/smarty-php/smarty.git
synced 2026-05-05 12:14:12 +02:00
fix mb_str_replace to work with utf8
This commit is contained in:
@@ -22,30 +22,8 @@
|
||||
*/
|
||||
function smarty_modifier_replace($string, $search, $replace)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (function_exists('mb_substr')) {
|
||||
return mb_str_replace($search, $replace, $string);
|
||||
} else {
|
||||
return str_replace($search, $replace, $string);
|
||||
}
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
|
||||
return smarty_mb_str_replace($search, $replace, $string);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user