summaryrefslogtreecommitdiffstats
path: root/system/helpers/text_helper.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2016-02-09 22:35:08 +0100
committerAndrey Andreev <narf@devilix.net>2016-02-09 22:35:08 +0100
commit477e08f1d6726809660e4841f389493541f7bc07 (patch)
tree785b12b53c5e46e317def1768558f33445ab2b1f /system/helpers/text_helper.php
parent2342256c076502cbaca86fcff2a1dbbfc49a1900 (diff)
parent39967987ebcc79fc867c1f7fa8d69cc65801f594 (diff)
Merge branch '3.0-stable' into develop
Fixed conflicts: user_guide_src/source/overview/at_a_glance.rst
Diffstat (limited to 'system/helpers/text_helper.php')
-rw-r--r--system/helpers/text_helper.php21
1 files changed, 18 insertions, 3 deletions
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 1fdbedda5..4f9210f2d 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) - 1; $i >= 0; $i--)
+ {
+ $length = strlen($matches[$i][0]);
+ $str = substr_replace(
+ $str,
+ str_repeat('#', $length),
+ $matches[$i][1],
+ $length
+ );
+ }
}
}