diff options
Diffstat (limited to '')
-rw-r--r-- | src/web/helpers/html.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/web/helpers/html.php b/src/web/helpers/html.php new file mode 100644 index 0000000..dc38e3a --- /dev/null +++ b/src/web/helpers/html.php @@ -0,0 +1,21 @@ +<?php /* Copyright (c) 2024 Freya Murphy */ + +function is_base64(string $data): bool { + return base64_encode(base64_decode($data, true)) === $data; +} + +function maybe_base64_encode(string $data): string { + if (is_base64($data)) { + return $data; + } else { + return base64_encode($data); + } +} + +function esc(string $data): string { + $data = trim(preg_replace('/\s\s+/', ' ', $data)); + $data = str_replace('&', '&', $data); + $data = str_replace('<', '<', $data); + $data = str_replace('>', '>', $data); + return $data; +} |