From 84ad6e3c5b2f74b82d17b289db62cdf88f18a95b Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 8 Jun 2025 02:36:28 +0400 Subject: feat: file title --- lib/utils.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib') diff --git a/lib/utils.php b/lib/utils.php index eb868a2..6b4b29e 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -40,4 +40,24 @@ function format_timestamp(int $timestamp_secs) } else { return "$days day" . ($days > 1 ? "s" : ""); } +} + +function str_safe(string $s, int|null $max_length, bool $remove_new_lines = true): string +{ + $output = $s; + + if ($remove_new_lines) { + $output = str_replace(PHP_EOL, "", $output); + } + + $output = htmlspecialchars($output); + $output = strip_tags($output); + + if ($max_length) { + $output = substr($output, 0, $max_length); + } + + $output = trim($output); + + return $output; } \ No newline at end of file -- cgit v1.2.3