From: Mischa POSLAWSKY Date: Thu, 19 Apr 2018 16:03:33 +0000 (+0200) Subject: nieuws: parse date using single regexp X-Git-Tag: v3.0~10 X-Git-Url: http://git.shiar.net/minimedit.git/commitdiff_plain/3da476bb04d8dcb7545a5c7eb328054c7ee20df3 nieuws: parse date using single regexp Equivalent but easier to maintain. --- diff --git a/nieuws.inc.php b/nieuws.inc.php index 7e723e4..f9fec6a 100644 --- a/nieuws.inc.php +++ b/nieuws.inc.php @@ -6,12 +6,11 @@ $monthname = ['?', function shownewsdate($url) { - $parts = pathinfo($url); - $year = pathinfo($parts['dirname'], PATHINFO_FILENAME); - @list ($month, $day) = explode('-', $parts['filename'], 3); + if (!preg_match('', $url, $parts)) return; global $monthname; - return sprintf('%s %s %s', - intval($day), $monthname[intval($month)], $year); + return implode(' ', array_filter([ + intval($parts[3]), $monthname[intval($parts[2])], $parts[1], + ])); } function shownewsarticle($url, $link = TRUE, $title = NULL)