From a7b673a1b60ad477d19ae0607f4d46e804ea831c Mon Sep 17 00:00:00 2001 From: rxu Date: Sat, 31 Aug 2024 23:21:33 +0700 Subject: [PATCH] [ticket/17387] Fix PHP warnings in search results PHPBB-17387 --- phpBB/includes/functions_content.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 2e52863ef0..3dded3c6e9 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -400,16 +400,14 @@ function get_context(string $text, array $words, int $length = 400): string $fragment_end = $end - $start + 1; // Find the first valid alphanumeric character in the fragment to don't cut words - if ($start > 0) + if ($start > 0 && preg_match('/[^a-zA-Z0-9][a-zA-Z0-9]/u', $fragment, $matches, PREG_OFFSET_CAPTURE)) { - preg_match('/[^a-zA-Z0-9][a-zA-Z0-9]/u', $fragment, $matches, PREG_OFFSET_CAPTURE); $fragment_start = (int) $matches[0][1] + 1; // first valid alphanumeric character } // Find the last valid alphanumeric character in the fragment to don't cut words - if ($end < $text_length - 1) + if ($end < $text_length - 1 && preg_match_all('/[a-zA-Z0-9][^a-zA-Z0-9]/u', $fragment, $matches, PREG_OFFSET_CAPTURE)) { - preg_match_all('/[a-zA-Z0-9][^a-zA-Z0-9]/u', $fragment, $matches, PREG_OFFSET_CAPTURE); $fragment_end = end($matches[0])[1]; // last valid alphanumeric character }