Files
smarty/libs/plugins/modifier.regex_replace.php

35 lines
878 B
PHP
Raw Normal View History

2002-01-31 20:49:40 +00:00
<?php
/**
2002-01-31 20:49:40 +00:00
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty regex_replace modifier plugin
*
* Type: modifier<br>
* Name: regex_replace<br>
2002-01-31 20:49:40 +00:00
* Purpose: regular epxression search/replace
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
* regex_replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param string|array
* @param string|array
* @return string
2002-01-31 20:49:40 +00:00
*/
function smarty_modifier_regex_replace($string, $search, $replace)
{
2005-03-21 14:09:50 +00:00
if (preg_match('!\W(\w+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) {
/* remove eval-modifier from $search */
$search = substr($search, 0, -strlen($match[1])) . str_replace('e', '', $match[1]);
}
2002-01-31 20:49:40 +00:00
return preg_replace($search, $replace, $string);
}
/* vim: set expandtab: */
?>