2) { $reststrone=strtoupper(explode(",", $outbits[1])[0]); $minusstr=""; if (strpos(strtoupper($reststrone), "W") !== false || strpos(strtoupper($reststrone), "S") !== false) { $minusstr="-"; } //echo "\n \$reststrone=" . $reststrone . " \$minusstr=" . $minusstr . "\n"; //$reststrtwo=strtoupper(explode(",", $outbits[1])[0]); if (!$lathfound && !$longhfound) { while (substr($outbits[0], $ideg, 1) <= '9' && substr($outbits[0], $ideg, 1) >= '0') { //echo "substr(\$outbits[0], \$ideg, 1)=" . substr($outbits[0], $ideg, 1) . "\n"; $spares=$degstrone; $degstrone=substr($outbits[0], $ideg, 1) . $spares; $ideg--; } $ideg=-1; while (substr($outbits[1], $ideg, 1) <= '9' && substr($outbits[1], $ideg, 1) >= '0') { $spares=$degstrtwo; $degstrtwo=substr($outbits[1], $ideg, 1) . $spares; $ideg--; } if (strpos($reststrone, "N") !== false || strpos($reststrone, "S") !== false) { if ($degstrone <= 90.0) { $hdrline="Latitude,Longitude,\n"; } } } $outct=substr($outbits[0],0,(strlen($outbits[0]) - strlen($degstrone))) . $minusstr . $degstrone; for ($iuyt=1; $iuyt (1 + $iuyt)) { $nextrestb=explode(",", $outbits[1 + $iuyt])[0]; } //echo "\n\$restb=" . $restb . "\n
"; $minstr=""; $secstr=""; $ideg=0; if (substr($restb, $ideg, 1) == '.' || (substr($restb, $ideg, 1) <= '9' && substr($restb, $ideg, 1) >= '0')) { $lastc=substr($restb, -1, 1); if ($lastc != "'" && $lastc != '"') { $lastc=""; } while (substr($restb, $ideg, 1) == '.' || (substr($restb, $ideg, 1) <= '9' && substr($restb, $ideg, 1) >= '0')) { if ($ideg >= 2) { if (strlen($secstr) == 2 && substr($restb, $ideg, 1) != '.') { $secstr.="."; } $secstr.=substr($restb, $ideg, 1); } else { $minstr.=substr($restb, $ideg, 1); } $ideg++; } $ideg++; while (!(substr(($restb . " "), $ideg, 1) == '.' || (substr(($restb . " "), $ideg, 1) <= '9' && substr(($restb . " "), $ideg, 1) >= '0'))) { $ideg++; } if (substr(($restb . " "), $ideg, 1) == '.' || (substr(($restb . " "), $ideg, 1) <= '9' && substr(($restb . " "), $ideg, 1) >= '0')) { //echo "\n secs found\n"; while (substr($restb, $ideg, 1) == '.' || (substr($restb, $ideg, 1) <= '9' && substr($restb, $ideg, 1) >= '0')) { if (strlen($secstr) == 2 && substr($restb, $ideg, 1) != '.') { $secstr.="."; } $secstr.=substr($restb, $ideg, 1); $ideg++; } } } if ($minstr == "") { $minstr="0"; } if ($secstr == "") { $secstr="0"; } echo "\$minstr=" . $minstr . " and \$secstr=" . $secstr . "\n"; if ($restb == "" || $ideg == 1) { $outct.=".0" . $outbits[$iuyt]; } else if (strpos(strtoupper($nextrestb), "W") !== false || strpos(strtoupper($nextrestb), "S") !== false) { $minusstr="-"; //echo "\n\$Minusstr=" . $minusstr . "\n \$restb=" . $restb . "\n \$degstrtwo=" . $degstrtwo . "\n
"; $outct.="." . str_replace($restb,explode('.',('' . ($minstr / 60.0 + $secstr / 3600.0 + 0.0000000001)))[1] . $lastc,substr($outbits[$iuyt],0,(strlen($outbits[$iuyt]) - strlen($degstrtwo))) . $minusstr . $degstrtwo); } else { //echo "\n\$MinusStr=" . $minusstr . "\n \$restb=" . $restb . "\n \$degstrtwo=" . $degstrtwo . "\n
"; $outct.="." . str_replace($restb,explode('.',('' . ($minstr / 60.0 + $secstr / 3600.0 + 0.0000000001)))[1] . $lastc,$outbits[$iuyt]); } $ideg=-1; $degstrtwo=""; //$minusstr=""; if (sizeof($outbits) > (1 + $iuyt)) { while (substr($outbits[1 + $iuyt], $ideg, 1) <= '9' && substr($outbits[1 + $iuyt], $ideg, 1) >= '0') { //echo "Substr(\$outbits[1 + \$iuyt], \$ideg, 1)=" . substr($outbits[1 + $iuyt], $ideg, 1) . "\n"; $spares=$degstrtwo; $degstrtwo=substr($outbits[1 + $iuyt], $ideg, 1) . $spares; $ideg--; } } } } return $hdrline . $outct; } function clean_csv_commas($csv, $indelimis) { // thanks to https://stackoverflow.com/questions/10739016/how-to-remove-commas-between-double-quotes-in-php global $reverseorder, $reversesuffix; $foundwordlatitude=false; $foundwordlongitude=false; $numbersfound=false; $under180=array(true, true); $under90=array(true, true); $until=true; $qdelim = '"'; $bqdelim = "'"; $altbqdelim = "&apos;"; $comma = ','; $altcomma = '&comma;'; $altqdelim = '&quot;'; $prevcomma=FALSE; $aftcomma=FALSE; if ($indelimis == "'") { $qdelim=$indelimis; $bqdelim='"'; $altqdelim = '&apos;'; $altbqdelim = '&quot;'; } $len = strlen($csv); $inside_block = FALSE; $out=''; $rep=''; for ($i=0; $i<$len; $i++) { if (ord($csv[$i]) < 32) { $inside_block=FALSE; $until=false; } else if ($csv[$i] == $qdelim) { if ($i == 0) { $prevcomma=FALSE; $inside_block=TRUE; } else if (($i + 1) == $len) { $aftcomma=FALSE; $inside_block=FALSE; } else { if ($csv[-1 + $i] == ',' || ord($csv[-1 + $i]) < 32) { $prevcomma=TRUE; } else { $prevcomma=FALSE; } if ($csv[1 + $i] == ',' || ord($csv[1 + $i]) < 32) { $aftcomma=TRUE; } else { $aftcomma=FALSE; } if ($inside_block) { if ($aftcomma) { $inside_block=FALSE; } } else { if ($prevcomma) { $inside_block=TRUE; } } } } //if ($until) { // $rep.="\n" . $csv[$i] . " \$inside_block=" . $inside_block . " \$prevcomma=" . $prevcomma . " \$aftcomma=" . $aftcomma; //} if ($csv[$i] == $comma && $inside_block) { if ($until) { $rep.="\n" . $csv[$i] . " \$inside-block=" . $inside_block . " \$prevcomma=" . $prevcomma . " \$aftcomma=" . $aftcomma; } $out.=$altcomma; } else if ($csv[$i] == $qdelim && $inside_block && !$aftcomma && !$prevcomma) { $out.=$altqdelim; } else if ($csv[$i] == $bqdelim && $inside_block) { $out.=$altbqdelim; } else { if ($indelimis == "" && !$reverseorder && ($csv[$i] == "\n" || $csv[$i] == "\r")) { $thisrecline=str_replace("\n","",str_replace("\r","",explode($csv[$i], $out)[-1 + sizeof(explode($csv[$i], $out))])); $twoormore=explode(',', $thisrecline); if (sizeof($twoormore) >= 2) { $ofinterest=0; for ($iuyt=0; $iuyt 180.0) { $under180[0]=false; $under90[0]=false; } if (abs(floatval(str_replace("'","",str_replace('"','',$twoormore[$iuyt])))) > 90.0) { $under90[0]=false; } $ofinterest=1; } else if (is_numeric(str_replace("'","",str_replace('"','',$twoormore[$iuyt]))) && $ofinterest == 1) { $numbersfound=true; if (abs(floatval(str_replace("'","",str_replace('"','',$twoormore[$iuyt])))) > 180.0) { $under180[1]=false; $under90[1]=false; } if (abs(floatval(str_replace("'","",str_replace('"','',$twoormore[$iuyt])))) > 90.0) { $under90[1]=false; } $ofinterest=2; } else if (!is_numeric(str_replace("'","",str_replace('"','',$twoormore[$iuyt]))) && !$numbersfound && !$foundwordlatitude && !$foundwordlongitude) { if (strpos(strtolower(str_replace("'","",str_replace('"','',$twoormore[$iuyt]))), "latitude") !== false) { $foundwordlatitude=true; } else if (strpos(strtolower(str_replace("'","",str_replace('"','',$twoormore[$iuyt]))), "longitude") !== false) { $foundwordlongitude=true; } else if (strpos("~" . strtolower(str_replace("'","",str_replace('"','',$twoormore[$iuyt]))), "~lat") !== false) { $foundwordlatitude=true; } else if (strpos("~" . strtolower(str_replace("'","",str_replace('"','',$twoormore[$iuyt]))), "~long") !== false) { $foundwordlongitude=true; } } } } } $out.=$csv[$i]; } } if ($indelimis == "") { //file_put_contents("xxx.xxx", "under90[0]=" . $under90[0] . " under90[1]=" . $under90[1] . " under180[0]=" . $under180[0] . " under180[1]=" . $under180[1] . "\n"); if (!$under180[0] || !$under180[1]) { $reverseorder=$reverseorder; } else if ($under90[0] && $under90[1]) { if (!$foundwordlongitude) { $reverseorder=true; //$reverseorder; $reversesuffix="
";
        } else {
        $reversesuffix="



"; } } else if ($under90[0] && $under180[1]) { //if (!$foundwordlongitude) { $reverseorder=true; //$reverseorder; $reversesuffix="
";
        //}
      } else if ($under180[0] && $under90[1]) {
        $reverseorder=false;   //$reverseorder;
        $reversesuffix="



"; } //file_put_contents("zerocsv.xxx", $csv); //file_put_contents("one_csv.xxx", $rep); //file_put_contents("onecsv.xxx", $out); $out=str_replace("'","",str_replace('"','',clean_csv_commas($out, "'"))); //file_put_contents("twocsv.xxx", $out); } return $out; } if (isset($_GET['csvfile'])) { $fname=str_replace("+"," ",urldecode($_GET['csvfile'])); $csvcont=''; if (strpos(strtolower($fname),"http") !== false) { $csvcont=dmscheck(file_get_contents($fname)); } else if (file_exists($fname)) { $csvcont=dmscheck(file_get_contents($fname)); } else if (strpos("~" . strtolower($fname),"~//") !== false) { $csvcont=dmscheck(file_get_contents("http:" . $fname)); } else if (strpos("~" . strtolower($fname),"~www.") !== false) { $csvcont=dmscheck(file_get_contents("http://" . $fname)); } else if (strpos(strtolower($fname),".com") !== false || strpos(strtolower($fname),".org") !== false) { $csvcont=dmscheck(file_get_contents("http://" . $fname)); } //file_put_contents("threecsv.xxx", '" . str_replace("\r","
",str_replace("\n","
",str_replace("\r\n","
",str_replace("'","",clean_csv_commas($csvcont,""))))) . "'" . ';">'); if ($reverseorder) { echo '" . str_replace("\r","
",str_replace("\n","
",str_replace("\r\n","
",str_replace("'","",clean_csv_commas($csvcont,""))))) . "" . $reversesuffix . "'" . ';">'; } else { echo '" . str_replace("\r","
",str_replace("\n","
",str_replace("\r\n","
",str_replace("'","",clean_csv_commas($csvcont,""))))) . "" . $reversesuffix . "'" . ';">'; } exit; } $prehtml = ""; $midhtml = ""; $posthtml = ""; function retval($inv) { if (strpos($inv, "E-") !== false) return "0"; return $inv; } ?> Survey Traverse Calculation - RJM Programming - Copyright © 2013 rjmprogramming.com.au all rights reserved.

' . "\n"; $htm .= ''; $posthtm .= '
' . "\n"; $posthtm .= ''; if (isset($_GET['coords'])) { echo '
' . "\n"; } else { echo ' ' . "\n"; echo ' ' . "\n"; } //} ?>