diff options
author | Andrey Andreev <narf@devilix.net> | 2016-01-29 12:29:57 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2016-01-29 12:29:57 +0100 |
commit | 6af9dd6e24687b6a7b9d14a058a47edcac761e61 (patch) | |
tree | fd56a379bb86cbe836fffe3fe3af95f49b99af2a /system/helpers | |
parent | 6a802289522abc85309527855d9dc2faa34f54e0 (diff) |
Fix #4407
Diffstat (limited to 'system/helpers')
-rw-r--r-- | system/helpers/text_helper.php | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 1fdbedda5..79aaf1492 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -275,13 +275,28 @@ if ( ! function_exists('word_censor')) foreach ($censored as $badword) { + $badword = str_replace('\*', '\w*?', preg_quote($badword, '/')); if ($replacement !== '') { - $str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/i", "\\1{$replacement}\\3", $str); + $str = preg_replace( + "/({$delim})(".$badword.")({$delim})/i", + "\\1{$replacement}\\3", + $str + ); } - else + elseif (preg_match_all("/{$delim}(".$badword."){$delim}/i", $str, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE)) { - $str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/ie", "'\\1'.str_repeat('#', strlen('\\2')).'\\3'", $str); + $matches = $matches[1]; + for ($i = count($matches); $i >= 0; $i--) + { + $length = strlen($matches[$i][0]); + $str = substr_replace( + $str, + str_repeat('#', $length), + $matches[$i][1], + $length + ); + } } } |