21 lines
584 B
PHP
21 lines
584 B
PHP
<?php
|
|
|
|
/**
|
|
* Normalizuje komunikat kolejki do zwykłego tekstu (wiersze = \n w JSON).
|
|
* Starsze wpisy HTML (<br>, tagi) są konwertowane na plain text.
|
|
*/
|
|
function normalizeQueueMessageText(string $text): string
|
|
{
|
|
$text = trim($text);
|
|
if ($text === '') {
|
|
return '';
|
|
}
|
|
|
|
$text = preg_replace('/<br\s*\/?>/i', "\n", $text) ?? $text;
|
|
$text = html_entity_decode(strip_tags($text), ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
|
$text = str_replace(["\r\n", "\r"], "\n", $text);
|
|
$text = preg_replace("/\n{3,}/", "\n\n", $text) ?? $text;
|
|
|
|
return trim($text);
|
|
}
|