diff options
| author | ilotterytea <iltsu@alright.party> | 2025-04-19 16:47:23 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-04-19 16:47:23 +0500 |
| commit | 9c2f42e423096bdf56b7f96e07221f6420b0e337 (patch) | |
| tree | 5cbcc6054f0727b4777590d6c25f6c66c68b0075 /src/utils.php | |
| parent | ad9ed65599cdcbd90fd6862caae23f5141cdfbf7 (diff) | |
feat: upload emotes
Diffstat (limited to 'src/utils.php')
| -rw-r--r-- | src/utils.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/utils.php b/src/utils.php new file mode 100644 index 0000000..59ecad4 --- /dev/null +++ b/src/utils.php @@ -0,0 +1,33 @@ +<?php +function generate_random_string(int $length): string +{ + $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + $output = ""; + + for ($i = 0; $i < $length; $i++) { + $charindex = random_int(0, strlen($chars) - 1); + $output .= $chars[$charindex]; + } + + return $output; +} + +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 |
