summaryrefslogtreecommitdiffstats
path: root/web/include/misc.php
blob: 15b5ceaef82815ea3a737ea80e013e8fdb660467 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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);
}