- Timestamp:
- Jun 20, 2013, 5:38:47 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/smarty/libs/plugins/modifier.regex_replace.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsModifier 6 7 */ 7 8 8 9 9 /** … … 13 13 * Name: regex_replace<br> 14 14 * Purpose: regular expression search/replace 15 * 15 16 * @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php 16 17 * regex_replace (Smarty online manual) 17 * @author 18 * @param string 19 * @param string|array 20 * @param string|array 18 * @author Monte Ohrt <monte at ohrt dot com> 19 * @param string $string input string 20 * @param string|array $search regular expression(s) to search for 21 * @param string|array $replace string(s) that should be replaced 21 22 * @return string 22 23 */ … … 24 25 { 25 26 if(is_array($search)) { 26 foreach($search as $idx => $s) 27 $search[$idx] = _smarty_regex_replace_check($s); 27 foreach($search as $idx => $s) { 28 $search[$idx] = _smarty_regex_replace_check($s); 29 } 28 30 } else { 29 $search = _smarty_regex_replace_check($search); 30 } 31 31 $search = _smarty_regex_replace_check($search); 32 } 32 33 return preg_replace($search, $replace, $string); 33 34 } 34 35 36 /** 37 * @param string $search string(s) that should be replaced 38 * @return string 39 * @ignore 40 */ 35 41 function _smarty_regex_replace_check($search) 36 42 { 37 if (($pos = strpos($search,"\0")) !== false) 38 $search = substr($search,0,$pos); 43 // null-byte injection detection 44 // anything behind the first null-byte is ignored 45 if (($pos = strpos($search,"\0")) !== false) { 46 $search = substr($search,0,$pos); 47 } 48 // remove eval-modifier from $search 39 49 if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) { 40 /* remove eval-modifier from $search */41 50 $search = substr($search, 0, -strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]); 42 51 } … … 44 53 } 45 54 46 /* vim: set expandtab: */47 48 55 ?>
Note: See TracChangeset
for help on using the changeset viewer.