| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-07-06 20:00:41 +00:00
										 |  |  |  * Smarty plugin | 
					
						
							|  |  |  |  * @package Smarty | 
					
						
							|  |  |  |  * @subpackage PluginsModifier | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-07-06 20:00:41 +00:00
										 |  |  |  * Smarty replace modifier plugin | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * Type:     modifier<br> | 
					
						
							|  |  |  |  * Name:     replace<br> | 
					
						
							|  |  |  |  * Purpose:  simple search/replace | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * @link http://smarty.php.net/manual/en/language.modifier.replace.php replace (Smarty online manual) | 
					
						
							|  |  |  |  * @author Monte Ohrt <monte at ohrt dot com>  | 
					
						
							|  |  |  |  * @author Uwe Tews  | 
					
						
							|  |  |  |  * @param string $  | 
					
						
							|  |  |  |  * @param string $  | 
					
						
							|  |  |  |  * @param string $  | 
					
						
							|  |  |  |  * @return string  | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | function smarty_modifier_replace($string, $search, $replace) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-06 20:00:41 +00:00
										 |  |  |     if (!function_exists('mb_str_replace')) { | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // simulate the missing PHP mb_str_replace function
 | 
					
						
							| 
									
										
										
										
											2010-07-06 20:00:41 +00:00
										 |  |  |         function mb_str_replace($needles, $replacements, $haystack) | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2010-07-06 20:00:41 +00:00
										 |  |  |             $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); | 
					
						
							|  |  |  |                 }  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             }  | 
					
						
							|  |  |  |             return $haystack; | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |     }  | 
					
						
							| 
									
										
										
										
											2009-08-10 17:52:26 +00:00
										 |  |  |     if (function_exists('mb_substr')) { | 
					
						
							| 
									
										
										
										
											2009-04-10 15:52:59 +00:00
										 |  |  |         return mb_str_replace($search, $replace, $string); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return str_replace($search, $replace, $string); | 
					
						
							|  |  |  |     }  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-06 20:00:41 +00:00
										 |  |  | ?>
 |