'; if (!empty($title)) { echo '
'; print_r($object); echo ''; } public static function table(string $tableName): string { return TABLENAME_PREFIX . $tableName; } public static function markdown(string $md, bool $clear=false, bool $line=true): string { $parseDown = new Parsedown(); $parseDown ->setBreaksEnabled(true) ->setSafeMode(true) ; if ($line) { $html = $parseDown->line($md); } else { $md = preg_replace_callback( '#( ){2,}#', static function ($m) { return str_repeat(' ', strlen($m[0])); }, $md ); $html = $parseDown->text($md); } $text = strip_tags($html); return $clear ? $text : $html; } public static function htmlEscape(string $html): string { return htmlentities($html, ENT_HTML5 | ENT_QUOTES); } public static function htmlMailEscape(string $html): string { return htmlspecialchars($html, ENT_HTML5 | ENT_QUOTES); } public static function csvEscape(string $text): string { $escaped = str_replace(['"', "\r\n", "\n"], ['""', '', ''], $text); $escaped = preg_replace("/^(=|\+|\-|\@)/", "'$1", $escaped); return '"' . $escaped . '"'; } public static function cleanFilename(string $title): string { $cleaned = preg_replace('[^a-zA-Z0-9._-]', '_', $title); return preg_replace(' {2,}', ' ', $cleaned); } public static function fromPostOrDefault(string $postKey, ?string $default = '') { return !empty($_POST[$postKey]) ? $_POST[$postKey] : $default; } public static function base64url_encode(string $input): string { return rtrim(strtr(base64_encode($input), '+/', '-_'), '='); } public static function base64url_decode(string $input): string { return base64_decode(str_pad(strtr($input, '-_', '+/'), strlen($input) % 4, '=', STR_PAD_RIGHT), true); } }