summaryrefslogtreecommitdiff
path: root/lib/utils.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils.php')
-rw-r--r--lib/utils.php20
1 files changed, 20 insertions, 0 deletions
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