From 02321c412ce40e42d37ab5d61cf46a7ecbb3164c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Wed, 26 Sep 2018 15:15:07 +0200 Subject: [PATCH] [ticket/15043] Update regexp PHPBB3-15043 --- phpBB/includes/functions_content.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index c400c52891..e99d0a4800 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -330,7 +330,7 @@ function get_context(string $text, array $words, int $length = 400) $text_length = utf8_strlen($text); // Replace all spaces/invisible characters with single spaces - $text = preg_replace("/[[:^print:] ]+/", ' ', $text); + $text = preg_replace("/\s+/", ' ', $text); // we need to turn the entities back into their original form, to not cut the message in between them $text = html_entity_decode($text); @@ -361,9 +361,11 @@ function get_context(string $text, array $words, int $length = 400) $start = $end = 0; foreach ($word_indizes as $indize => $word) { - if ($end+$characters_per_word+utf8_strlen($word) < $indize) + // Check if the next word can be inside the current fragment of text + if ($end + $characters_per_word + utf8_strlen($word) < $indize) { $fragment = utf8_substr($text, $start, $end-$start); + if ($start != 0) { $fragment = '... ' . $fragment; @@ -371,16 +373,16 @@ function get_context(string $text, array $words, int $length = 400) $fragments[] = $fragment; - $start = $indize-($characters_per_word/2); + $start = $indize - ($characters_per_word / 2); // Start fragment at the begining of a word - $end = $start = ($start > 0) ? (utf8_strpos($text, ' ', $start-1)+1) : 0; + $end = $start = ($start > 0) ? (utf8_strpos($text, ' ', $start - 1) + 1) : 0; } $end += $characters_per_word; // End fragment at the end of a word $substring = utf8_substr($text, $start, $end-$start); - $end = $start+utf8_strrpos($substring, ' '); + $end = $start + utf8_strrpos($substring, ' '); } $fragment = utf8_substr($text, $start, $end-$start);