[ticket/15043] Update regexp

PHPBB3-15043
This commit is contained in:
Rubén Calvo 2018-09-26 15:15:07 +02:00 committed by Ruben Calvo
parent 13f7a8f82f
commit 02321c412c
No known key found for this signature in database

View file

@ -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)
{
// 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;