diff options
| author | Nathan Kinkade <kinkade@measurementlab.net> | 2019-08-27 13:05:48 -0600 |
|---|---|---|
| committer | Nathan Kinkade <kinkade@measurementlab.net> | 2019-08-27 13:05:48 -0600 |
| commit | a6c179d56973e382205c8583568d635c37f814c8 (patch) | |
| tree | d144141439adac21f0c1bc2fc2caa85fd8135039 /lib/smarty-3.1.33/plugins/shared.mb_str_replace.php | |
| parent | 34972193073432105b8659407af5a914b3686f81 (diff) | |
Updates smarty to v3.1.33.
Diffstat (limited to 'lib/smarty-3.1.33/plugins/shared.mb_str_replace.php')
| -rw-r--r-- | lib/smarty-3.1.33/plugins/shared.mb_str_replace.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/smarty-3.1.33/plugins/shared.mb_str_replace.php b/lib/smarty-3.1.33/plugins/shared.mb_str_replace.php new file mode 100644 index 0000000..206cf9e --- /dev/null +++ b/lib/smarty-3.1.33/plugins/shared.mb_str_replace.php @@ -0,0 +1,53 @@ +<?php +/** + * Smarty shared plugin + * + * @package Smarty + * @subpackage PluginsShared + */ +if (!function_exists('smarty_mb_str_replace')) { + /** + * Multibyte string replace + * + * @param string|string[] $search the string to be searched + * @param string|string[] $replace the replacement string + * @param string $subject the source string + * @param int &$count number of matches found + * + * @return string replaced string + * @author Rodney Rehm + */ + function smarty_mb_str_replace($search, $replace, $subject, &$count = 0) + { + if (!is_array($search) && is_array($replace)) { + return false; + } + if (is_array($subject)) { + // call mb_replace for each single string in $subject + foreach ($subject as &$string) { + $string = smarty_mb_str_replace($search, $replace, $string, $c); + $count += $c; + } + } elseif (is_array($search)) { + if (!is_array($replace)) { + foreach ($search as &$string) { + $subject = smarty_mb_str_replace($string, $replace, $subject, $c); + $count += $c; + } + } else { + $n = max(count($search), count($replace)); + while ($n--) { + $subject = smarty_mb_str_replace(current($search), current($replace), $subject, $c); + $count += $c; + next($search); + next($replace); + } + } + } else { + $parts = mb_split(preg_quote($search), $subject); + $count = count($parts) - 1; + $subject = implode($replace, $parts); + } + return $subject; + } +} |
