summaryrefslogtreecommitdiff
path: root/src/web/helpers/html.php
blob: dc38e3a1df2660d7b246b520b5462f66544861c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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('&', '&amp;', $data);
	$data = str_replace('<', '&lt;', $data);
	$data = str_replace('>', '&gt;', $data);
	return $data;
}