28 lines
836 B
PHP
28 lines
836 B
PHP
<?php
|
|
|
|
class Util
|
|
{
|
|
/**
|
|
* Entfernt alle Zeichen außer A-Z, a-z, 0-9 sowie - und _
|
|
* @param string $string Eingabe mit möglicherweise ungültigen Zeichen
|
|
* @return string Eingabestring mit allen ungültigen Zeichen entfernt
|
|
*/
|
|
static function removeIllegalCharacters(string $string): string
|
|
{
|
|
return preg_replace("/[^a-zA-Z0-9_-]/", "", $string);
|
|
}
|
|
|
|
/**
|
|
* Öffnet eine Datei und gibt JSON-Inhalte als Array zurück
|
|
* @param string $filename Dateipfad
|
|
* @return mixed Array mit Key-Value Paaren
|
|
*/
|
|
static function parseJsonFromFile(string $filename): mixed
|
|
{
|
|
$file = fopen($filename, "r") or die("Unable to open file!");
|
|
$fileContent = fread($file, filesize($filename));
|
|
fclose($file);
|
|
|
|
return json_decode($fileContent);
|
|
}
|
|
} |