mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/17387] Fix PHP warnings in search results
PHPBB-17387
This commit is contained in:
parent
23f872d138
commit
a7b673a1b6
1 changed files with 2 additions and 4 deletions
|
@ -400,16 +400,14 @@ function get_context(string $text, array $words, int $length = 400): string
|
||||||
$fragment_end = $end - $start + 1;
|
$fragment_end = $end - $start + 1;
|
||||||
|
|
||||||
// Find the first valid alphanumeric character in the fragment to don't cut words
|
// 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
|
$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
|
// 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
|
$fragment_end = end($matches[0])[1]; // last valid alphanumeric character
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue