translation/templating
diff --git a/utils.php b/utils.php
index c3a9620..6086153 100644
--- a/utils.php
+++ b/utils.php
@@ -1,5 +1,6 @@
<?php
-function generateRandomString($length = 96) {
+function generateRandomString($length = 96)
+{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
@@ -9,16 +10,21 @@
return $randomString;
}
-function getClientIP():string
+function getClientIP(): string
{
- $keys=array('HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR','HTTP_X_FORWARDED','HTTP_FORWARDED_FOR','HTTP_FORWARDED','REMOTE_ADDR');
- foreach($keys as $k)
- {
- if (!empty($_SERVER[$k]) && filter_var($_SERVER[$k], FILTER_VALIDATE_IP))
- {
+ $keys = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR');
+ foreach ($keys as $k) {
+ if (!empty($_SERVER[$k]) && filter_var($_SERVER[$k], FILTER_VALIDATE_IP)) {
return $_SERVER[$k];
}
}
return false;
}
-?>
+
+function format(string $string, array $values)
+{
+ foreach ($values as $key => $value) {
+ $string = str_replace("{{{$key}}}", $value, $string);
+ }
+ return $string;
+}