From 3da476bb04d8dcb7545a5c7eb328054c7ee20df3 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 19 Apr 2018 18:03:33 +0200 Subject: [PATCH] nieuws: parse date using single regexp Equivalent but easier to maintain. --- nieuws.inc.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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) -- 2.30.0