Files
auswertung
bootstrap
classes
config
controller
dashboard
datepicker
jquery
js
language
lib
old
smarty
demo
lexer
libs
plugins
block.textformat.php
function.counter.php
function.cycle.php
function.fetch.php
function.html_checkboxes.php
function.html_image.php
function.html_options.php
function.html_radios.php
function.html_select_date.php
function.html_select_time.php
function.html_table.php
function.mailto.php
function.math.php
modifier.capitalize.php
modifier.date_format.php
modifier.debug_print_var.php
modifier.escape.php
modifier.mb_wordwrap.php
modifier.regex_replace.php
modifier.replace.php
modifier.spacify.php
modifier.truncate.php
modifiercompiler.cat.php
modifiercompiler.count_characters.php
modifiercompiler.count_paragraphs.php
modifiercompiler.count_sentences.php
modifiercompiler.count_words.php
modifiercompiler.default.php
modifiercompiler.escape.php
modifiercompiler.from_charset.php
modifiercompiler.indent.php
modifiercompiler.lower.php
modifiercompiler.noprint.php
modifiercompiler.string_format.php
modifiercompiler.strip.php
modifiercompiler.strip_tags.php
modifiercompiler.to_charset.php
modifiercompiler.unescape.php
modifiercompiler.upper.php
modifiercompiler.wordwrap.php
outputfilter.trimwhitespace.php
shared.escape_special_chars.php
shared.literal_compiler_param.php
shared.make_timestamp.php
shared.mb_str_replace.php
shared.mb_unicode.php
variablefilter.htmlspecialchars.php
sysplugins
Autoloader.php
Smarty.class.php
SmartyBC.class.php
bootstrap.php
debug.tpl
CHANGELOG.md
COMPOSER_RELEASE_NOTES.txt
INHERITANCE_RELEASE_NOTES.txt
LICENSE
NEW_FEATURES.txt
README
README.md
SMARTY_2_BC_NOTES.txt
SMARTY_3.0_BC_NOTES.txt
SMARTY_3.1_NOTES.txt
composer.json
expectException
smarty2
smarty_3
Smarty-2.6.28.zip
smarty-3.1.29.zip
media
sql
survey
templates
test
tinymce
.gitignore
config.inc.php
todo.txt
survey/lib/smarty/libs/plugins/modifier.regex_replace.php
2023-03-14 14:47:50 +01:00

56 lines
1.7 KiB
PHP

<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty regex_replace modifier plugin
* Type: modifier
* Name: regex_replace
* 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 $string input string
* @param string|array $search regular expression(s) to search for
* @param string|array $replace string(s) that should be replaced
* @param int $limit the maximum number of replacements
*
* @return string
*/
function smarty_modifier_regex_replace($string, $search, $replace, $limit = -1)
{
if (is_array($search)) {
foreach ($search as $idx => $s) {
$search[ $idx ] = _smarty_regex_replace_check($s);
}
} else {
$search = _smarty_regex_replace_check($search);
}
return preg_replace($search, $replace, $string, $limit);
}
/**
* @param string $search string(s) that should be replaced
*
* @return string
* @ignore
*/
function _smarty_regex_replace_check($search)
{
// null-byte injection detection
// anything behind the first null-byte is ignored
if (($pos = strpos($search, "\0")) !== false) {
$search = substr($search, 0, $pos);
}
// remove eval-modifier from $search
if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[ 1 ], 'e') !== false)) {
$search = substr($search, 0, -strlen($match[ 1 ])) . preg_replace('![e\s]+!', '', $match[ 1 ]);
}
return $search;
}