From 95ce6b8cea9bb79f82e43f99639fa3371a809cbb Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Mon, 21 Jun 2021 18:58:59 +0200 Subject: Add function parseArguments --- core/functions.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/functions.php b/core/functions.php index 4b3eabd..5fd1b39 100644 --- a/core/functions.php +++ b/core/functions.php @@ -199,6 +199,26 @@ function getMarkdownImageURLs(string $text): array { return []; } +#=============================================================================== +# Parse argument string to array +#=============================================================================== +function parseArguments(?string $argv): array { + if($argv) { + foreach(explode('|', $argv) as $delimeter) { + $part = explode('=', $delimeter); + + $argumentK = $part[0] ?? NULL; + $argumentV = $part[1] ?? TRUE; + + if(preg_match('#^[[:word:]]+$#', $argumentK)) { + $arguments[strtoupper($argumentK)] = $argumentV; + } + } + } + + return $arguments ?? []; +} + #=============================================================================== # Parser for datetime formatted strings [YYYY-MM-DD HH:II:SS] #=============================================================================== -- cgit v1.2.3