From fef495ff7b2c5501f5f896d7222da3eb1d1fa5a4 Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Sat, 9 Aug 2014 23:02:38 +0200 Subject: [PATCH] Fixed some spelling errors and tuned the regexes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced a-zåäö with \p{L} and fixed spelling errors and replaced $program with PROGRAM on line 122. Also added \u modifer to more places for UTF-8, just in case. --- HISTORY | 6 ++++++ check_smhiwarn.php | 14 +++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/HISTORY b/HISTORY index 57a42ce..4d189b9 100644 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,9 @@ +0.4 - 2014-08-09 + Added /u modifier to more preg_matches for UTF-8 + Replaced a-zåäö with \p{L} + Fixed a couple of spelling errors and missing words + Replaced $program with PROGRAM on line 122 + 0.3 - 2014-08-03 Added /u modifier to the preg_match for UTF-8 diff --git a/check_smhiwarn.php b/check_smhiwarn.php index 9edbc4d..3f6ec21 100755 --- a/check_smhiwarn.php +++ b/check_smhiwarn.php @@ -26,7 +26,7 @@ define ("CRITICAL", 2); define ("UNKNOWN", 3); // Define version and program -define ("VERSION", 0.2); +define ("VERSION", 0.4); define ("PROGRAM", $argv[0]); // Function for printing usage @@ -116,10 +116,10 @@ if ($district == 'list') } // Check if the district exists -if (!preg_grep("/^$district$/", $availDistricts)) +if (!preg_grep("/^$district$/u", $availDistricts)) { print "$district does not exists\n"; - print "List all avaliable districts by \"$program 'list'\"\n"; + print "List all avaliable districts by \"" . PROGRAM . " 'list'\"\n"; exit(UNKNOWN); } @@ -133,15 +133,15 @@ $data = curl_exec($ch); curl_close($ch); // Regex the area (1st paranthesis is area, 2nd is warning class, 3rd is warning msg) -preg_match("/($district)(?:: )(?:Varning klass )([1-3]+)(?:,\s)([-a-z0-9åäö.,&\s]*)/iu", +preg_match("/($district)(?:: )(?:Varning klass )([1-3]+)(?:,\s)([-0-9\p{L}.,&\s]*)/iu", $data, $matches); // Count how many warnings are issued and issue a critical if more than one -preg_match_all("/$district/", $data, $counts); +preg_match_all("/$district/u", $data, $counts); $numberMatches = (count($counts[0])); if ($numberMatches > 1) { - print "More than one warning are issued for $district, check smhi.se!"; + print "More than one warning is issued for $district, check smhi.se!"; exit(CRITICAL); } @@ -160,7 +160,7 @@ else switch ($warnLevel) { case 0: - print "No warnings issued $district"; + print "No warnings issued for $district"; exit(OK); case 1: print "Class 1 warning issued for $district: $warnMsg";