18 lines
630 B
PHP
18 lines
630 B
PHP
<?php
|
|
$text = trim((string) ($text ?? ''));
|
|
$mode = $mode ?? 'line';
|
|
$escape = static fn(string $value): string => htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
|
|
|
if ($mode === 'words') {
|
|
$words = preg_split('/\s+/u', $text, -1, PREG_SPLIT_NO_EMPTY);
|
|
$out = [];
|
|
foreach ($words as $index => $word) {
|
|
$out[] = '<span class="kick-word" style="--w:' . $index . '">' . $escape($word) . '</span>';
|
|
}
|
|
return implode(' ', $out);
|
|
}
|
|
|
|
$lines = preg_split('/\R/u', $text);
|
|
$lines = array_map(static fn(string $line): string => $escape(trim($line)), $lines);
|
|
|
|
return implode($mode === 'br' ? '<br>' : ' ', $lines); |