/PHPconvertDMSToDecimal

Convert degrees / minutes / seconds to decimal degrees in PHP

Primary LanguagePHPMIT LicenseMIT

PHPconvertDMSToDecimal

A PHP function that will convert a coordinate in DMS (degrees / minutes / seconds) to decimal degrees.

Strictly speaking it will also accept decimal degrees. I wanted a function that could parse any latitude or longitude that a user may input.

Test cases are included, and the output should look like this:

 N 53 03 47.7   =>      53.06325
 s53 03 47.7    =>      -53.06325
 E53  03  47.7  =>      53.06325
 w53 03 47.7    =>      -53.06325
  53 03 47.7 n  =>      53.06325
 53 03 47.7S    =>      -53.06325
 53  03  47.7e  =>      53.06325
 W 53 03 47.7   =>      -53.06325
 N53 03 47.7    =>      53.06325
 s.53.03.47.7   =>      53.06325
 E53.03.47.7    =>      53.06325
 w53..03..47.7  =>      53.06325
 n53.03.47.7    =>      53.06325
  53.03.47.7 S  =>      53.06325
 53.03.47.7e    =>      53.06325
 53..03..47.7W  =>      53.06325
 N.53.03.47.7   =>      53.06325
 s53.03.47.7    =>      53.06325
 E-53-03-47.7   =>      53.06325
 w53-03-47.7    =>      -53.06325
 n53--03--47.7  =>      53.06325
 S53-03-47.7    =>      -53.06325
  53-03-47.7 e  =>      53.06325
 53-03-47.7W    =>      -53.06325
 53--03--47.7N  =>      53.06325
 s-53-03-47.7   =>      -53.06325
 E53-03-47.7    =>      53.06325
53.06325w       =>      -53.06325
53.06325        =>      53.06325
53.06325 s      =>      -53.06325
53.06325 N      =>      53.06325
-53.06325       =>      -53.06325
53 03 47.7      =>      53.06325
-53 03 47.7     =>      -53.06325
53 03 47.7W     =>      -53.06325
-53º 03' 47.7"  =>      -53.06325
53º 03' 47.7"   =>      53.06325
53º 03' 47.7"s  =>      -53.06325
 N 144 35 26    =>      144.59055555556
 s144 35 26     =>      -144.59055555556
E 144  35 26    =>      144.59055555556
144 35 26w      =>      -144.59055555556
N144.35.26      =>      144.59055555556
 144.35.26s     =>      -144.59055555556
-144 35 26      =>      -144.59055555556
144º 35' 26"w   =>      -144.59055555556
45°43'51''N	=>	45.730833333333
009°44'23''E	=>	9.7397222222222