diff options
Diffstat (limited to 'web/include/misc.php')
-rw-r--r-- | web/include/misc.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/web/include/misc.php b/web/include/misc.php new file mode 100644 index 0000000..15b5cea --- /dev/null +++ b/web/include/misc.php @@ -0,0 +1,36 @@ +<?php +/** + * Misc utility functions + * + * @package volse.faktura.web + */ + +/** + * Escape an input string so that it's safe fr use in a html context. + * + * @param string $input The unescaped input string. + * + * @return A string that's safe for use in html tags. + */ +function esc_html(?string $input): string { + if (empty($input)) { + return ''; + } + + return htmlspecialchars($input, ENT_NOQUOTES | ENT_HTML5); +} + +/** + * Escape input so that it's safe for use in html attrubutes. + * + * @param string $input The unescaped input string. + * + * @return A string that's safe for use in html attibutes. + */ +function esc_attr(?string $input): string { + if (empty($input)) { + return ''; + } + + return htmlspecialchars($input, ENT_QUOTES | ENT_HTML5); +} |