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

36 lines
900 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>
2006-03-03 14:42:01 +00:00
* Purpose: regular expression 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)
{
2006-03-08 14:37:37 +00:00
if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) {
2005-03-21 14:09:50 +00:00
/* remove eval-modifier from $search */
$search = substr($search, 0, -strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]);
2005-03-21 14:09:50 +00:00
}
2002-01-31 20:49:40 +00:00
return preg_replace($search, $replace, $string);
}
/* vim: set expandtab: */
?>