function Harvest() { $xml = get($this->url, "bioGUID"); //echo $xml; //exit(); // Extract records from RSS2 feed $dom = new DOMDocument(); $dom->loadXML($xml); $xpath = new DOMXPath($dom); // Add namespaces to XPath to ensure our queries work $xpath->registerNamespace("rss", "http://purl.org/rss/1.0/"); $xpath->registerNamespace("dc", "http://purl.org/dc/elements/1.1/"); $nodeCollection = $xpath->query("//item"); foreach ($nodeCollection as $node) { $item = new stdclass(); $nc = $xpath->query("title", $node); foreach ($nc as $n) { $item->title = $n->firstChild->nodeValue; } $nc = $xpath->query("link", $node); foreach ($nc as $n) { $item->link = $n->firstChild->nodeValue; $item->id = $n->firstChild->nodeValue; } $nc = $xpath->query("description", $node); foreach ($nc as $n) { $item->description = $n->firstChild->nodeValue; } $nc = $xpath->query("pubDate", $node); foreach ($nc as $n) { $item->created = date("Y-m-d H:i:s", strtotime($n->firstChild->nodeValue)); $item->updated = date("Y-m-d H:i:s", strtotime($n->firstChild->nodeValue)); } // Get what we want... $item->links = array(); // Extract details $rows = explode("\n", $item->description); foreach ($rows as $row) { // Database identifiers ------------------------------------------------------------ // IPNI if (preg_match_all("/\n\t\t\t\t\t(\\{\\{IPNI\\|(?<id>[0-9]+\\-[123])\\|([^\\}\\}]+|(?R))*\\}\\})\n\t\t\t\t\t/x", $row, $m)) { array_push($item->links, array('lsid' => 'urn:lsid:ipni.org:names:' . $m['id'][0])); } // ITIS if (preg_match_all("/\n\t\t\t\t\t(\\{\\{ITIS\\|(?<id>[0-9]+)([^\\}\\}]+|(?R))*\\}\\})\n\t\t\t\t\t/x", $row, $m)) { array_push($item->links, array('itis' => $m['id'][0])); } // MSW if (preg_match_all("/\n\t\t\t\t\t(\\{\\{MSWsp\\|(?<id>[0-9]+)([^\\}\\}]+|(?R))*\\}\\})\n\t\t\t\t\t/x", $row, $m)) { array_push($item->links, array('msw' => $m['id'][0])); } // Index Fungorum if (preg_match_all("/\n\t\t\t\t\t(\\[http:\\/\\/www.indexfungorum.org\\/Names\\/NamesRecord.asp\\?RecordID=(?<id>[0-9]+)\\s+)\n\t\t\t\t\t/x", $row, $m)) { array_push($item->links, array('lsid' => 'urn:lsid:indexfungorum.org:names:' . $m['id'][0])); } // Locality information ------------------------------------------------------------ // Geotagging // Type locality: Kenya, Kakamega Forest, 1590 m., 00º21'N, 034º51'E.<br /> $row = str_replace("º", "°", $row); $row = str_replace("º", "°", $row); // Type locality if (preg_match('/(?<degreesLatitude>\\d+)°(?<minutesLatitude>\\d+)\'(?<hemisphereLatitude>[S|N]),\\s+(?<degreesLongitude>\\d+)°(?<minutesLongitude>\\d+)\'(?<hemisphereLongitude>[W|E])/', $row, $matches)) { // latitude $seconds = 0; $minutes = 0; $degrees = $matches['degreesLatitude']; if (isset($matches['minutesLatitude'])) { $minutes = $matches['minutesLatitude']; } if (isset($matches['secondsLatitude'])) { $seconds = $matches['secondsLatitude']; } $latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['hemisphereLatitude']); $latlong['latitude'] = $latitude; // longitude $seconds = 0; $minutes = 0; $degrees = $matches['degreesLongitude']; if (isset($matches['minutesLongitude'])) { $minutes = $matches['minutesLongitude']; } if (isset($matches['secondsLongitude'])) { $seconds = $matches['secondsLongitude']; } $longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['hemisphereLongitude']); $latlong['longitude'] = $longitude; $item->latitude = $latlong['latitude']; $item->longitude = $latlong['longitude']; } } // Bibliographic references -------------------------------------------------------- // extract reference block $in_refs = false; $ref_text = ''; foreach ($rows as $row) { if (preg_match('/^==\\s*References\\s*==/', $row)) { $in_refs = true; } if (preg_match('/^\\*/', $row) && $in_refs) { $ref_text .= $row . "\n"; } if (preg_match('/^==\\s*^(References)\\s*==/', $row)) { $in_refs = false; } } $refs = explode("\n", trim($ref_text)); $item->payload->bibliography = array(); foreach ($refs as $ref) { // Need to add this to feedmaker to we add it to the feed array_push($item->payload->bibliography, $ref); /* Lookup reference guids, time consuming, maybe defer... $obj = new stdclass; $matched = parse_wikispecies_ref($ref, $obj, 0); if ($matched) { $url = 'http://bioguid.info/openurl/?genre=article'; $url .= '&title=' . urlencode($obj->journal); $url .= '&volume=' . $obj->volume; $url .= '&spage=' . $obj->spage; $url .= '&date=' . $obj->year; $url .= '&display=json'; $j = get($url); $ref = json_decode($j); if ($ref->status == 'ok') { if (isset($ref->doi)) { array_push($item->links, array('doi' => $ref->doi)); } if (isset($ref->pmid)) { array_push($item->links, array('pmid' => $ref->pmid)); } if (isset($ref->hdl)) { array_push($item->links, array('hdl' => $ref->hdl)); } if (isset($ref->url)) { array_push($item->links, array('url' => $ref->url)); } } } */ } $this->StoreFeedItem($item); } }
/** * @brief * * @param text Text which may contain latitude and longitudes * * @return Array of points (as class with fields latitude and longitude) */ function points_from_text($text) { $text = str_replace("\n", " ", $text); $text = str_replace("\\n", " ", $text); $points = array(); //echo $text; $matched = false; if (!$matched) { // lat 13.869°N, long 89.620°W if (preg_match_all('/( lat \\s* (?<latitude_degrees>([0-9]{1,2})) (?<latitude_minutes>(\\.[0-9]+)) ° (?<latitude_hemisphere>[N|S]) , \\s* long \\s* (?<longitude_degrees>([0-9]{1,2})) (?<longitude_minutes>(\\.[0-9]+)) ° (?<longitude_hemisphere>[W|E]) )/xu', $text, $matches, PREG_PATTERN_ORDER)) { $num = count($matches[0]); for ($i = 0; $i < $num; $i++) { $pt = new stdclass(); $degrees = $matches['latitude_degrees'][$i] + $matches['latitude_minutes'][$i]; $pt->latitude = $degrees; if ($matches['latitude_hemisphere'][$i] == 'S') { $pt->latitude *= -1; } $degrees = $matches['longitude_degrees'][$i] + $matches['longitude_minutes'][$i]; $pt->longitude = $degrees; if ($matches['longitude_hemisphere'][$i] == 'W') { $pt->longitude *= -1; } $points[] = $pt; } $matched = true; } } if (!$matched) { // http://www.biodiversitylibrary.org/page/40824927 // 48 30' 33" E, 13 00' 01" S (long first then lat) if (preg_match_all('/( (?<longitude_degrees>([0-9]{1,2})) \\s+ (?<longitude_minutes>([0-9]+)) \' \\s+ (?<longitude_seconds>\\d+) " \\s+ (?<longitude_hemisphere>[W|E]) , \\s+ (?<latitude_degrees>([0-9]{1,2})) \\s+ (?<latitude_minutes>([0-9]+)) \' \\s+ (?<latitude_seconds>\\d+) " \\s+ (?<latitude_hemisphere>[N|S]) )/xu', $text, $matches, PREG_PATTERN_ORDER)) { $num = count($matches[0]); for ($i = 0; $i < $num; $i++) { $pt = new stdclass(); if (isset($matches['latitude_seconds'][$i])) { $seconds = $matches['latitude_seconds'][$i]; } $minutes = $matches['latitude_minutes'][$i]; $degrees = $matches['latitude_degrees'][$i]; $pt->latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['latitude_hemisphere'][$i]); if (isset($matches['longitude_seconds'][$i])) { $seconds = $matches['longitude_seconds'][$i]; } $minutes = $matches['longitude_minutes'][$i]; $degrees = $matches['longitude_degrees'][$i]; $pt->longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['longitude_hemisphere'][$i]); $points[] = $pt; } $matched = true; } } if (!$matched) { if (preg_match_all('/( (?<latitude_degrees>([0-9]{1,2}))([°]) \\s* ((?<latitude_minutes>([0-9]+)(\\.[0-9]+)?))? [\']? \\s* (?<latitude_hemisphere>[N|S]) [,] \\s* ((?<longitude_degrees>([0-9]{1,3}))([°])?)? \\s* (?<longitude_minutes>([0-9]+)(\\.[0-9]+)?) [\']? \\s* (?<longitude_hemisphere>[W|E]) )/xu', $text, $matches, PREG_PATTERN_ORDER)) { $num = count($matches[0]); for ($i = 0; $i < $num; $i++) { $pt = new stdclass(); $seconds = 0; $minutes = 0; $degrees = $matches['latitude_degrees'][$i]; if (isset($matches['latitude_minutes'][$i])) { $minutes = $matches['latitude_minutes'][$i]; } if (isset($matches['latitude_seconds'][$i])) { $seconds = $matches['latitude_seconds'][$i]; } $pt->latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['latitude_hemisphere'][$i]); $seconds = 0; $minutes = 0; $degrees = $matches['longitude_degrees'][$i]; if (isset($matches['longitude_minutes'][$i])) { $minutes = $matches['longitude_minutes'][$i]; } if (isset($matches['longitude_seconds'][$i])) { $seconds = $matches['longitude_seconds'][$i]; } $pt->longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['longitude_hemisphere'][$i]); $points[] = $pt; } $matched = true; } } // http://www.biodiversitylibrary.org/page/3387645 if (!$matched) { if (preg_match_all('/( (?<latitude_degrees>([0-9]{1,2}))\\.(?<latitude_minutes>([0-9]+)) (?<latitude_hemisphere>[N|S]) [,]\\s* (?<longitude_degrees>([0-9]{1,3}))\\.(?<longitude_minutes>([0-9]+)) (?<longitude_hemisphere>[W|E]) )/xu', $text, $matches, PREG_PATTERN_ORDER)) { $num = count($matches[0]); for ($i = 0; $i < $num; $i++) { $pt = new stdclass(); $seconds = 0; $minutes = 0; $degrees = $matches['latitude_degrees'][$i]; if (isset($matches['latitude_minutes'][$i])) { $minutes = $matches['latitude_minutes'][$i]; } $pt->latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['latitude_hemisphere'][$i]); $seconds = 0; $minutes = 0; $degrees = $matches['longitude_degrees'][$i]; if (isset($matches['longitude_minutes'][$i])) { $minutes = $matches['longitude_minutes'][$i]; } $pt->longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['longitude_hemisphere'][$i]); $points[] = $pt; } $matched = true; } } if (!$matched) { if (preg_match_all('/( (?<latitude_degrees>([0-9]{1,2}))([°]) (?<latitude_hemisphere>[N|S]) [,] \\s* ((?<longitude_degrees>([0-9]{1,3}))([°])?)? (?<longitude_hemisphere>[W|E]) )/xu', $text, $matches, PREG_PATTERN_ORDER)) { //print_r($matches); $num = count($matches[0]); for ($i = 0; $i < $num; $i++) { $pt = new stdclass(); $seconds = 0; $minutes = 0; $degrees = $matches['latitude_degrees'][$i]; $pt->latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['latitude_hemisphere'][$i]); $seconds = 0; $minutes = 0; $degrees = $matches['longitude_degrees'][$i]; $pt->longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['longitude_hemisphere'][$i]); $points[] = $pt; } $matched = true; } } if (!$matched) { // 54° 20' 80" N.; y9°09'30"E if (preg_match_all('/( (?<latitude_degrees>([0-9]{1,2}))[°|�] \\s* (?<latitude_minutes>([0-9]+))\' \\s* ((?<latitude_seconds>([0-9]+))")? \\s* (?<latitude_hemisphere>[N|S])\\.? [,|;]\\s* (?<longitude_degrees>([0-9]{1,3}))[°|�] \\s* (?<longitude_minutes>([0-9]+))\' \\s* ((?<longitude_seconds>([0-9]+))")? \\s* (?<longitude_hemisphere>[W|E])\\.? )/xu', $text, $matches, PREG_PATTERN_ORDER)) { $num = count($matches[0]); for ($i = 0; $i < $num; $i++) { $pt = new stdclass(); if (isset($matches['latitude_seconds'][$i])) { $seconds = $matches['latitude_seconds'][$i]; } $minutes = $matches['latitude_minutes'][$i]; $degrees = $matches['latitude_degrees'][$i]; $pt->latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['latitude_hemisphere'][$i]); if (isset($matches['longitude_seconds'][$i])) { $seconds = $matches['longitude_seconds'][$i]; } $minutes = $matches['longitude_minutes'][$i]; $degrees = $matches['longitude_degrees'][$i]; $pt->longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['longitude_hemisphere'][$i]); $points[] = $pt; } $matched = true; } } if (!$matched) { // 38 18' 30" N, 123 4' W if (preg_match_all('/( (?<latitude_degrees>([0-9]{1,2})) \\s+ (?<latitude_minutes>([0-9]+))\' \\s+ ((?<latitude_seconds>([0-9]+))")? \\s* (?<latitude_hemisphere>[N|S]) [,|;]\\s* (?<longitude_degrees>([0-9]{1,3})) \\s+ (?<longitude_minutes>([0-9]+))\' \\s+ ((?<longitude_seconds>([0-9]+))")? \\s* (?<longitude_hemisphere>[W|E]) )/xu', $text, $matches, PREG_PATTERN_ORDER)) { $num = count($matches[0]); for ($i = 0; $i < $num; $i++) { $pt = new stdclass(); if (isset($matches['latitude_seconds'][$i])) { $seconds = $matches['latitude_seconds'][$i]; } $minutes = $matches['latitude_minutes'][$i]; $degrees = $matches['latitude_degrees'][$i]; $pt->latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['latitude_hemisphere'][$i]); if (isset($matches['longitude_seconds'][$i])) { $seconds = $matches['longitude_seconds'][$i]; } $minutes = $matches['longitude_minutes'][$i]; $degrees = $matches['longitude_degrees'][$i]; $pt->longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['longitude_hemisphere'][$i]); $points[] = $pt; } $matched = true; } } if (!$matched) { // 0224' N 4259' E if (preg_match_all('/( (?<latitude_degrees>([0-9]{2})) (?<latitude_minutes>([0-9]{2}))\' \\s* (?<latitude_hemisphere>[N|S]) \\s+ (?<longitude_degrees>([0-9]{2})) (?<longitude_minutes>([0-9]{2}))\' \\s* (?<longitude_hemisphere>[W|E]) )/xu', $text, $matches, PREG_PATTERN_ORDER)) { $num = count($matches[0]); for ($i = 0; $i < $num; $i++) { $pt = new stdclass(); $seconds = ''; if (isset($matches['latitude_seconds'][$i])) { $seconds = $matches['latitude_seconds'][$i]; } $minutes = $matches['latitude_minutes'][$i]; $degrees = $matches['latitude_degrees'][$i]; $pt->latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['latitude_hemisphere'][$i]); $seconds = ''; if (isset($matches['longitude_seconds'][$i])) { $seconds = $matches['longitude_seconds'][$i]; } $minutes = $matches['longitude_minutes'][$i]; $degrees = $matches['longitude_degrees'][$i]; $pt->longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['longitude_hemisphere'][$i]); $points[] = $pt; } $matched = true; } } if (!$matched) { //http://biostor.org/reference/14507 // No hemisphere, but for this example it's N and E // 36°58', 127 °57' if (preg_match_all('/( (?<latitude_degrees>([0-9]{1,2})) [°] \\s? (?<latitude_minutes>([0-9]+))\' [,]\\s (?<longitude_degrees>([0-9]{1,3})) [°] \\s? (?<longitude_minutes>([0-9]+))\' )/xu', $text, $matches, PREG_PATTERN_ORDER)) { $num = count($matches[0]); for ($i = 0; $i < $num; $i++) { $pt = new stdclass(); if (isset($matches['latitude_seconds'][$i])) { $seconds = $matches['latitude_seconds'][$i]; } $minutes = $matches['latitude_minutes'][$i]; $degrees = $matches['latitude_degrees'][$i]; $pt->latitude = degrees2decimal($degrees, $minutes, $seconds, 'N'); if (isset($matches['longitude_seconds'][$i])) { $seconds = $matches['longitude_seconds'][$i]; } $minutes = $matches['longitude_minutes'][$i]; $degrees = $matches['longitude_degrees'][$i]; $pt->longitude = degrees2decimal($degrees, $minutes, $seconds, 'E'); $points[] = $pt; } $matched = true; } } if (!$matched) { // http://biostor.org/reference/4047 // 34°49'N 24°32'W if (preg_match_all('/( (?<latitude_degrees>([0-9]{1,2})) [°] (?<latitude_minutes>([0-9]+))\' (?<latitude_hemisphere>[N|S]) \\s+ (?<longitude_degrees>([0-9]{1,3})) [°] (?<longitude_minutes>([0-9]+))\' (?<longitude_hemisphere>[W|E]) )/xu', $text, $matches, PREG_PATTERN_ORDER)) { $num = count($matches[0]); for ($i = 0; $i < $num; $i++) { $pt = new stdclass(); $seconds = ''; if (isset($matches['latitude_seconds'][$i])) { $seconds = $matches['latitude_seconds'][$i]; } $minutes = $matches['latitude_minutes'][$i]; $degrees = $matches['latitude_degrees'][$i]; $pt->latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['latitude_hemisphere'][$i]); $seconds = ''; if (isset($matches['longitude_seconds'][$i])) { $seconds = $matches['longitude_seconds'][$i]; } $minutes = $matches['longitude_minutes'][$i]; $degrees = $matches['longitude_degrees'][$i]; $pt->longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['longitude_hemisphere'][$i]); $points[] = $pt; } $matched = true; } } if (!$matched) { // http://biostor.org/reference/55225 // N10°23'31"; W 83°58'04" if (preg_match_all('/( (?<latitude_hemisphere>[N|S]) \\s* (?<latitude_degrees>([0-9]{1,2}))[°] (?<latitude_minutes>([0-9]+))\' (?<latitude_seconds>([0-9]+))" \\s* ; \\s+ (?<longitude_hemisphere>[W|E]) \\s* (?<longitude_degrees>([0-9]{1,2}))[°] (?<longitude_minutes>([0-9]+))\' (?<longitude_seconds>([0-9]+))" )/xu', $text, $matches, PREG_PATTERN_ORDER)) { $num = count($matches[0]); for ($i = 0; $i < $num; $i++) { $pt = new stdclass(); if (isset($matches['latitude_seconds'][$i])) { $seconds = $matches['latitude_seconds'][$i]; } $minutes = $matches['latitude_minutes'][$i]; $degrees = $matches['latitude_degrees'][$i]; $pt->latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['latitude_hemisphere'][$i]); if (isset($matches['longitude_seconds'][$i])) { $seconds = $matches['longitude_seconds'][$i]; } $minutes = $matches['longitude_minutes'][$i]; $degrees = $matches['longitude_degrees'][$i]; $pt->longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['longitude_hemisphere'][$i]); $points[] = $pt; } $matched = true; } } return $points; }
function toPoint($matches) { $point = array(); $degrees = $minutes = $seconds = 0; if (isset($matches['latitude_seconds'])) { $seconds = $matches['latitude_seconds']; } $minutes = $matches['latitude_minutes']; $degrees = $matches['latitude_degrees']; $point['latitude'] = degrees2decimal($degrees, $minutes, $seconds, $matches['latitude_hemisphere']); $degrees = $minutes = $seconds = 0; if (isset($matches['longitude_seconds'])) { $seconds = $matches['longitude_seconds']; } $minutes = $matches['longitude_minutes']; $degrees = $matches['longitude_degrees']; $point['longitude'] = degrees2decimal($degrees, $minutes, $seconds, $matches['longitude_hemisphere']); return $point; }
/** * @brief Extract latitude and longitude from a text string * * @param str Text string * @para latlong Latitude and longitude (as members of an array) * * @result True if successfully parsed * */ function IsLatLong($str, &$latlong) { $result = false; $matches = array(); // remove prime (backtick) $str = str_replace("′", "'", $str); $str = trim($str, '('); $str = rtrim($str, ')'); //echo $str . '<br/>'; // 115.59E/37.64N if (!$result) { if (preg_match('/(?<longitude>\\d+(.\\d+)?)(?<longitudeHemisphere>[W|E])\\/(?<latitude>\\d+(.\\d+)?)(?<latitudeHemisphere>[S|N])/', $str, $matches)) { //print_r($matches); $longitude = $matches['longitude']; if ($matches['longitudeHemisphere'] == 'W') { $longitude *= -1.0; } $latlong['longitude'] = $longitude; $latitude = $matches['latitude']; if ($matches['latitudeHemisphere'] == 'S') { $latitude *= -1.0; } $latlong['latitude'] = $latitude; $result = true; } } if (!$result) { // S 9°3'; W 72°44' if (preg_match('/(?<latitudeHemisphere>[S|N])\\s*(?<latitude>\\d+)°((?<latitudeMinutes>\\d+)\')?((?<latitudeSeconds>\\d+)")?[;|,]\\s*(?<longitudeHemisphere>[W|E])\\s*(?<longitude>\\d+)°((?<longitudeMinutes>\\d+)\')?((?<longitudeSeconds>\\d+)")?/', $str, $matches)) { //print_r($matches); // longitude $longitude = $matches['longitude']; if (isset($matches['longitudeMinutes'])) { $longitude += $matches['longitudeMinutes'] / 60.0; } if (isset($matches['longitudeSeconds'])) { $longitude += $matches['longitudeSeconds'] / 60.0; } if ($matches['longitudeHemisphere'] == 'W') { $longitude *= -1.0; } $latlong['longitude'] = $longitude; // latitude $latitude = $matches['latitude']; if (isset($matches['latitudeMinutes'])) { $latitude += $matches['latitudeMinutes'] / 60.0; } if (isset($matches['latitudeSeconds'])) { $latitude += $matches['latitudeSeconds'] / 3600.0; } if ($matches['latitudeHemisphere'] == 'S') { $latitude *= -1.0; } $latlong['latitude'] = $latitude; $result = true; } } //36°57'N, 10°37'E if (!$result) { if (preg_match('/(?<degreesLatitude>\\d+)°(\\s*(?<minutesLatitude>\\d+(.\\d+)?)\')?((?<secondsLatitude>\\d+(.\\d+)?)(\'\'|"))?\\s*(?<hemisphereLatitude>[S|N])(;|,|–|\\/)?\\s*(?<degreesLongitude>\\d+)°(\\s*(?<minutesLongitude>\\d+(.\\d+)?)\')?((?<secondsLongitude>\\d+(.\\d+)?)(\'\'|"))?\\s*(?<hemisphereLongitude>[W|E])/', $str, $matches)) { $result = true; //print_r($matches); // latitude $seconds = 0; $minutes = 0; $degrees = $matches['degreesLatitude']; if (isset($matches['minutesLatitude'])) { $minutes = $matches['minutesLatitude']; } if (isset($matches['secondsLatitude'])) { $seconds = $matches['secondsLatitude']; } $latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['hemisphereLatitude']); $latlong['latitude'] = $latitude; // longitude $seconds = 0; $minutes = 0; $degrees = $matches['degreesLongitude']; if (isset($matches['minutesLongitude'])) { $minutes = $matches['minutesLongitude']; } if (isset($matches['secondsLongitude'])) { $seconds = $matches['secondsLongitude']; } $longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['hemisphereLongitude']); $latlong['longitude'] = $longitude; } } // 39:49:35N; 3:08:50E if (!$result) { if (preg_match('/(?<degreesLatitude>\\d+)(:(?<minutesLatitude>\\d+))?(:(?<secondsLatitude>\\d+))?(?<hemisphereLatitude>[S|N])(;|,)?\\s*(?<degreesLongitude>\\d+)(:(?<minutesLongitude>\\d+))?(:(?<secondsLongitude>\\d+))?(?<hemisphereLongitude>[W|E])/', $str, $matches)) { $result = true; //print_r($matches); // latitude $seconds = 0; $minutes = 0; $degrees = $matches['degreesLatitude']; if (isset($matches['minutesLatitude'])) { $minutes = $matches['minutesLatitude']; } if (isset($matches['secondsLatitude'])) { $seconds = $matches['secondsLatitude']; } $latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['hemisphereLatitude']); $latlong['latitude'] = $latitude; // longitude $seconds = 0; $minutes = 0; $degrees = $matches['degreesLongitude']; if (isset($matches['minutesLongitude'])) { $minutes = $matches['minutesLongitude']; } if (isset($matches['secondsLongitude'])) { $seconds = $matches['secondsLongitude']; } $longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['hemisphereLongitude']); $latlong['longitude'] = $longitude; } } // S 4.45' W 73.57' if (!$result) { if (preg_match('/(?<hemisphereLatitude>[S|N]) (?<degreesLatitude>\\d+(.\\d+)?)\' (?<hemisphereLongitude>[W|E]) (?<degreesLongitude>\\d+(.\\d+)?)\'/', $str, $matches)) { $result = true; //print_r($matches); // latitude $seconds = 0; $minutes = 0; $degrees = $matches['degreesLatitude']; if (isset($matches['minutesLatitude'])) { $minutes = $matches['minutesLatitude']; } if (isset($matches['secondsLatitude'])) { $seconds = $matches['secondsLatitude']; } $latitude = degrees2decimal($degrees, $minutes, $seconds, $matches['hemisphereLatitude']); $latlong['latitude'] = $latitude; // longitude $seconds = 0; $minutes = 0; $degrees = $matches['degreesLongitude']; if (isset($matches['minutesLongitude'])) { $minutes = $matches['minutesLongitude']; } if (isset($matches['secondsLongitude'])) { $seconds = $matches['secondsLongitude']; } $longitude = degrees2decimal($degrees, $minutes, $seconds, $matches['hemisphereLongitude']); $latlong['longitude'] = $longitude; } } return $result; }