From f77d60436d4e7f3b2e5159129fdaca897f25c9dd Mon Sep 17 00:00:00 2001 From: phl0 Date: Fri, 4 Dec 2020 11:30:40 +0100 Subject: [PATCH] Only calculate Lat/Lon if QRA loc has even number of chars --- application/libraries/Qra.php | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/application/libraries/Qra.php b/application/libraries/Qra.php index 2da16a6b..c058efec 100644 --- a/application/libraries/Qra.php +++ b/application/libraries/Qra.php @@ -119,20 +119,24 @@ $var_dist = ""; function qra2latlong($strQRA) { - $strQRA = strtoupper($strQRA); - if (strlen($strQRA) == 4) $strQRA .= "MM"; - if (!preg_match('/^[A-Z]{2}[0-9]{2}[A-Z]{2}$/',$strQRA)) return false; - list($a,$b,$c,$d,$e,$f) = str_split($strQRA,1); - $a = ord($a) - ord('A'); - $b = ord($b) - ord('A'); - $c = ord($c) - ord('0'); - $d = ord($d) - ord('0'); - $e = ord($e) - ord('A'); - $f = ord($f) - ord('A'); - $nLong = ($a*20) + ($c*2) + (($e+0.5)/12) - 180; - $nLat = ($b*10) + $d + (($f+0.5)/24) - 90; - $arLatLong = array($nLat,$nLong); - return($arLatLong); + if (strlen($strQRA) %2 == 0) { + $strQRA = strtoupper($strQRA); + if (strlen($strQRA) == 4) $strQRA .= "MM"; + if (!preg_match('/^[A-Z]{2}[0-9]{2}[A-Z]{2}$/',$strQRA)) return false; + list($a,$b,$c,$d,$e,$f) = str_split($strQRA,1); + $a = ord($a) - ord('A'); + $b = ord($b) - ord('A'); + $c = ord($c) - ord('0'); + $d = ord($d) - ord('0'); + $e = ord($e) - ord('A'); + $f = ord($f) - ord('A'); + $nLong = ($a*20) + ($c*2) + (($e+0.5)/12) - 180; + $nLat = ($b*10) + $d + (($f+0.5)/24) - 90; + $arLatLong = array($nLat,$nLong); + return($arLatLong); + } else { + return array(0, 0); + } } -/* End of file Qra.php */ \ No newline at end of file +/* End of file Qra.php */