diff options
author | Thomas Lange <code@nerdmind.de> | 2021-06-21 18:58:59 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2021-06-21 18:58:59 +0200 |
commit | 95ce6b8cea9bb79f82e43f99639fa3371a809cbb (patch) | |
tree | 74fdec761f7326b0f6e1cf30858fd47391b519b1 | |
parent | 57019638f3b72c42d9b72cab6f060537edbee038 (diff) | |
download | blog-95ce6b8cea9bb79f82e43f99639fa3371a809cbb.tar.gz blog-95ce6b8cea9bb79f82e43f99639fa3371a809cbb.tar.xz blog-95ce6b8cea9bb79f82e43f99639fa3371a809cbb.zip |
Add function parseArguments
-rw-r--r-- | core/functions.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/functions.php b/core/functions.php index 4b3eabd..5fd1b39 100644 --- a/core/functions.php +++ b/core/functions.php @@ -200,6 +200,26 @@ function getMarkdownImageURLs(string $text): array { } #=============================================================================== +# 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] #=============================================================================== function parseDatetime($datetime, $format): string { |