1 <?php
2 /**
3 * Smarty plugin
4 *
5 * @package Smarty
6 * @subpackage PluginsModifier
7 */
9 /**
10 * Smarty replace modifier plugin
11 *
12 * Type: modifier<br>
13 * Name: replace<br>
14 * Purpose: simple search/replace
15 *
16 * @link http://smarty.php.net/manual/en/language.modifier.replace.php replace (Smarty online manual)
17 * @author Monte Ohrt <monte at ohrt dot com>
18 * @author Uwe Tews
19 * @param string $
20 * @param string $
21 * @param string $
22 * @return string
23 */
24 function smarty_modifier_replace($string, $search, $replace)
25 {
26 if (!function_exists("mb_str_replace")) {
27 // simulate the missing PHP mb_str_replace function
28 function mb_str_replace($needle, $replacement, $haystack)
29 {
30 $needle_len = mb_strlen($needle);
31 $replacement_len = mb_strlen($replacement);
32 $pos = mb_strpos($haystack, $needle, 0);
33 while ($pos !== false) {
34 $haystack = mb_substr($haystack, 0, $pos) . $replacement
35 . mb_substr($haystack, $pos + $needle_len);
36 $pos = mb_strpos($haystack, $needle, $pos + $replacement_len);
37 }
38 return $haystack;
39 }
40 }
41 if (function_exists('mb_substr')) {
42 return mb_str_replace($search, $replace, $string);
43 } else {
44 return str_replace($search, $replace, $string);
45 }
46 }
48 ?>