Blame www/smarty/plugins/modifier.regex_replace.php
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
/**
|
|
Chris PeBenito |
696b41 |
* Smarty plugin
|
|
Chris PeBenito |
696b41 |
* @package Smarty
|
|
Chris PeBenito |
696b41 |
* @subpackage plugins
|
|
Chris PeBenito |
696b41 |
*/
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
/**
|
|
Chris PeBenito |
696b41 |
* Smarty regex_replace modifier plugin
|
|
Chris PeBenito |
696b41 |
*
|
|
Chris PeBenito |
696b41 |
* Type: modifier
|
|
Chris PeBenito |
696b41 |
* Name: regex_replace
|
|
Chris PeBenito |
696b41 |
* Purpose: regular epxression search/replace
|
|
Chris PeBenito |
696b41 |
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
|
|
Chris PeBenito |
696b41 |
* regex_replace (Smarty online manual)
|
|
Chris PeBenito |
696b41 |
* @param string
|
|
Chris PeBenito |
696b41 |
* @param string|array
|
|
Chris PeBenito |
696b41 |
* @param string|array
|
|
Chris PeBenito |
696b41 |
* @return string
|
|
Chris PeBenito |
696b41 |
*/
|
|
Chris PeBenito |
696b41 |
function smarty_modifier_regex_replace($string, $search, $replace)
|
|
Chris PeBenito |
696b41 |
{
|
|
Chris PeBenito |
696b41 |
if (preg_match('!\W(\w+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) {
|
|
Chris PeBenito |
696b41 |
/* remove eval-modifier from $search */
|
|
Chris PeBenito |
696b41 |
$search = substr($search, 0, -strlen($match[1])) . str_replace('e', '', $match[1]);
|
|
Chris PeBenito |
696b41 |
}
|
|
Chris PeBenito |
696b41 |
return preg_replace($search, $replace, $string);
|
|
Chris PeBenito |
696b41 |
}
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
/* vim: set expandtab: */
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
?>
|