mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 19:34:27 +02:00
move replacement func
This commit is contained in:
@@ -23,6 +23,21 @@
|
|||||||
*/
|
*/
|
||||||
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_RESOURCE_CHAR_SET)
|
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_RESOURCE_CHAR_SET)
|
||||||
{
|
{
|
||||||
|
if (!function_exists('mb_str_replace') && function_exists('mb_strlen')) {
|
||||||
|
// simulate the missing PHP mb_str_replace function
|
||||||
|
function mb_str_replace($needle, $replacement, $haystack)
|
||||||
|
{
|
||||||
|
$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) {
|
switch ($esc_type) {
|
||||||
case 'html':
|
case 'html':
|
||||||
return htmlspecialchars($string, ENT_QUOTES, $char_set);
|
return htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||||
@@ -91,21 +106,6 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_
|
|||||||
default:
|
default:
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
if (!function_exists("mb_str_replace")) {
|
|
||||||
// simulate the missing PHP mb_str_replace function
|
|
||||||
function mb_str_replace($needle, $replacement, $haystack)
|
|
||||||
{
|
|
||||||
$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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Reference in New Issue
Block a user