<?php
 // template_wiki.php
 // Wikipedia List of makeovers
 // RJM Programming
 // September, 2017
 ini_set('max_execution_time', 6000);

 $listsofar=";;";
 
 function bitsaround($errmsg) {
   return "<!doctype html><html><head><title>Wikipedia List of Latitude and Longitude Makeovers - RJM Programming - September, 2017</title><style> body { background-color:pink; }  form { background-color:yellow; } </style></head><body><br><h1>Wikipedia List Webpage Containing Latitude and Longitude Makeover</h1><br><br><h3>" . $errmsg . "</h3><br><br><form target='_self' method='GET' action='./template_wiki.php'><a target=_blank title='Wik" . "ipedia' href='http://www.wiki" . "pedia.org'>Wiki" . "pedia</a> 'List of' Concept 'of/in/on' Country webpage URL: <input type='text' style='width:40%;' name='wikip" . "ediaurl' id='wikip" . "ediaurl' value='https://en.wiki" . "pedia.org/wiki/List_o" . "f_{concept}_o" . "f/in_{country}'></input>&nbsp;&nbsp;<input onclick=\" var ov=document.getElementById('wikipediaurl').value; if (ov.length > 0) { location.href=document.URL.split('#')[0].split('?')[0] + '?wikipediaurl=' + encodeURIComponent(ov);  }  \" type='button' value='Makeover'></input></form></body></html>";
 }
 
 function capsall($inid) {
   $retvs=explode(" ",str_replace("_"," ",$inid));
   $sofar=strtoupper(substr($retvs[0],0,1)) . strtolower(substr($retvs[0],1));
   for ($ii=1; $ii<sizeof($retvs); $ii++) {
     $sofar.=" " . strtoupper(substr($retvs[$ii],0,1)) . strtolower(substr($retvs[$ii],1));
   }
   return $sofar;
 }
  
 if (isset($_GET['wikip' . 'ediaurl'])) {
   $getwikiurl=$_GET['wikip' . 'ediaurl'];
   if (strpos($getwikiurl,"//") === false) $getwikiurl=urldecode($_GET['wiki' . 'pediaurl']);
   if (sizeof(explode("_",$getwikiurl)) >= 5 && sizeof(explode("_of_",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))) >= 3 && strpos(strtolower($getwikiurl), "list_o" . "f_") !== false && strpos(strtolower($getwikiurl), "wikip" . "edia.org") !== false) {
     $wcont=@file_get_contents($getwikiurl);
     if (strpos($wcont,"E</span") !== false || strpos($wcont,"W</span") !== false) {
     $delim="/";
     if (strpos(dirname(__FILE__), $delim) === false) $delim=substr("\\",0.1);
     $extratempcont=file_get_contents(dirname(__FILE__) . $delim . "template_wiki.php");
     $tempcont=explode("?" . ">",str_replace("<" . explode("<" . "?" . "php", substr($extratempcont,1))[0], "", $extratempcont))[0] . "?" . ">\n";
     $ucountry=explode("_of_",explode("?",explode("#",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))[0])[0])[-1 + sizeof(explode("_of_",explode("?",explode("#",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))[0])[0]))];
     $uspcountry=capsall($ucountry);
     $uconcept=strtoupper(substr(explode("_",explode("_of_",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))[1])[0],0,1)) . substr(explode("_",explode("_of_",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))[1])[0],1);
     $uspconcept=capsall($uconcept);
     //echo str_replace("&","&amp;",str_replace("\n","<br>",str_replace("<","&lt;",str_replace(">","&gt;",$tempcont))));
     //exit;
     
     $ynft="display:BLOCK;";
     if (strpos(strtolower($ucountry), "australia") !== false) $ynft="youl" . "lnev" . "erfin" . "dthis";
     file_put_contents("this_wiki.php",
     str_replace("Wate" . "rfalls",$uspconcept,
     str_replace($ynft,"display:NONE;",
     str_replace('"Aust' . 'ralia"','"' . $uspcountry . '"',
     str_replace("_waterf" . "alls.php",strtolower("_" . $uconcept) . ".php",
     str_replace("austr" . "alia_water" . "falls.php",strtolower($ucountry . "_" . $uconcept) . ".php",
     str_replace("Aust" . "ralia Water" . "falls",$uspcountry . " " . $uspconcept,
     str_replace("aust" . "ralia_water" . "falls.php",strtolower($ucountry . "_" . $uconcept) . ".php",
     str_replace("https://en.wik" . "ipedia.o" . "rg/wiki/List_of_w" . "aterfalls_of_Au" . "stralia",$getwikiurl,
     $tempcont)))))))));
     header("Location: ./this_wiki.php?rand=" . rand());
     exit;
     } else if (strpos($wcont,"' E<") !== false || strpos($wcont,"' W<") !== false) {
     $delim="/";
     if (strpos(dirname(__FILE__), $delim) === false) $delim=substr("\\",0.1);
     $extratempcont=file_get_contents(dirname(__FILE__) . $delim . "template_wiki.php");
     $tempcont=explode("?" . ">",str_replace("<" . explode("<" . "?" . "php", substr($extratempcont,1))[0], "", $extratempcont))[1] . "?" . ">\n";
     $ucountry=explode("_of_",explode("?",explode("#",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))[0])[0])[-1 + sizeof(explode("_of_",explode("?",explode("#",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))[0])[0]))];
     $uspcountry=capsall($ucountry);
     $uconcept=strtoupper(substr(explode("_",explode("_of_",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))[1])[0],0,1)) . substr(explode("_",explode("_of_",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))[1])[0],1);
     $uspconcept=capsall($uconcept);
     //echo str_replace("&","&amp;",str_replace("\n","<br>",str_replace("<","&lt;",str_replace(">","&gt;",$tempcont))));
     //exit;
     
     $ynft="display:BLOCK;";
     if (strpos(strtolower($ucountry), "australia") !== false) $ynft="youl" . "lnev" . "erfin" . "dthis";
     file_put_contents("this_wiki.php",
     str_replace("Po" . "rts",$uspconcept,
     str_replace($ynft,"display:NONE;",
     str_replace('"Aust' . 'ralia"','"' . $uspcountry . '"',
     str_replace("_po" . "rts.php",strtolower("_" . $uconcept) . ".php",
     str_replace("austr" . "alia_po" . "rts.php",strtolower($ucountry . "_" . $uconcept) . ".php",
     str_replace("Aust" . "ralia Po" . "rts",$uspcountry . " " . $uspconcept,
     str_replace("aust" . "ralia_po" . "rts.php",strtolower($ucountry . "_" . $uconcept) . ".php",
     str_replace("https://en.wik" . "ipedia.o" . "rg/wiki/List_of_p" . "orts_in_Au" . "stralia",$getwikiurl,
     $tempcont)))))))));
     header("Location: ./this_wiki.php?rand=" . rand());
     exit;
     } else if (trim($wcont) == "") {
     echo bitsaround("Sorry, you have an non-existant URL.");
     } else if (strpos($wcont,"atitude") !== false && strpos($wcont,"ongitude") !== false) {
     $wcont=fixit(true, $wcont);
     if (strpos($wcont,"' E<") !== false || strpos($wcont,"' W<") !== false || strpos($wcont,"'E<") !== false || strpos($wcont,"'W<") !== false) {
     $delim="/";
     if (strpos(dirname(__FILE__), $delim) === false) $delim=substr("\\",0.1);
     $extratempcont=file_get_contents(dirname(__FILE__) . $delim . "template_wiki.php");
     $tempcont=explode("?" . ">",str_replace("<" . explode("<" . "?" . "php", substr($extratempcont,1))[0], "", $extratempcont))[1] . "?" . ">\n";
     $ucountry=explode("_of_",explode("?",explode("#",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))[0])[0])[-1 + sizeof(explode("_of_",explode("?",explode("#",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))[0])[0]))];
     $uspcountry=capsall($ucountry);
     $uconcept=strtoupper(substr(explode("_",explode("_of_",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))[1])[0],0,1)) . substr(explode("_",explode("_of_",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))[1])[0],1);
     $uspconcept=capsall($uconcept);
     //echo str_replace("&","&amp;",str_replace("\n","<br>",str_replace("<","&lt;",str_replace(">","&gt;",$tempcont))));
     //exit;
     
     $ynft="display:BLOCK;";
     if (strpos(strtolower($ucountry), "australia") !== false) $ynft="youl" . "lnev" . "erfin" . "dthis";
     file_put_contents("this_wiki.php",
     str_replace("Po" . "rts",$uspconcept,
     str_replace($ynft,"display:NONE;",
     str_replace('"Aust' . 'ralia"','"' . $uspcountry . '"',
     str_replace("_po" . "rts.php",strtolower("_" . $uconcept) . ".php",
     str_replace("austr" . "alia_po" . "rts.php",strtolower($ucountry . "_" . $uconcept) . ".php",
     str_replace("Aust" . "ralia Po" . "rts",$uspcountry . " " . $uspconcept,
     str_replace("aust" . "ralia_po" . "rts.php",strtolower($ucountry . "_" . $uconcept) . ".php",
     str_replace("https://en.wik" . "ipedia.o" . "rg/wiki/List_of_p" . "orts_in_Au" . "stralia",$getwikiurl,
     $tempcont)))))))));
     header("Location: ./this_wiki.php?fixit=y&rand=" . rand());
     exit;
     } else {
     echo bitsaround("Sorry, you have an ineligible contents (has no valid latitude and longitude data) for that URL.");
     }
     } else {
     echo bitsaround("Sorry, you have an ineligible contents (has no latitude and longitude) for that URL.");
     }
   } else {
     echo bitsaround("Sorry, you have an ineligible URL." . sizeof(explode("_of_",str_replace("_in_","_of_",str_replace("_on_","_of_",str_replace("_by_","_of_",$getwikiurl))))));
   }
 } else {
   echo bitsaround("Sorry, you have no ?wikip" . "ediaurl=[Wikipe" . "dia-List_o" . "f_{concept}_o" . "f_{Country}-URL] defined.  Eg. " . "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",explode("#",$_SERVER['REQUEST_URI'])[0])[0] . "?wiki" . "pediaurl=" . urlencode("https://en.wikip" . "edia.org/wiki/List_o" . "f_wate" . "rfalls_o" . "f_Austr" . "alia"));
 }
 exit;
?>
<?php
// australia_waterfalls.php
// RJM Programming
// September, 2017
// Thanks to Wikipedia at https://en.wikipedia.org/wiki/List_of_waterfalls_of_Australia
ini_set('max_execution_time', 6000);

 $listsofar=";;";

 function selcreate($def) {
   $ret=$def;
   $selstr='<select onchange=" window.location=this.value; "><option value="' . str_replace(" ", "_", strtolower($def)) . '_waterfalls.php">' . $def . '</option>';
   $cnt=0;
   foreach (glob("*_waterfalls.php") as $filename) {
    if (strpos(($filename . "*"), (str_replace(" ", "_", strtolower($def)) . '_waterfalls.php*')) === false) {
     $cnt++;
     $newidea=str_replace("_", " ", str_replace("_waterfalls.php", "", strtolower($filename)));
     $newideas=explode(" ", $newidea);
     $ideas=strtoupper(substr($newideas[0],0,1)) . strtolower(substr($newideas[0],1));
     for ($ii=1; $ii<sizeof($newideas); $ii++) {
       $ideas.=(" " . strtoupper(substr($newideas[$ii],0,1)) . strtolower(substr($newideas[$ii],1)));
     }
     $selstr.='<option value="' . $filename . '">' . $ideas . '</option>';
    }
   } 
   if ($cnt > 0) return $selstr . "</select>";  
   return $ret;
 }
 
 function extractnums($fromn) {
   $rn=0.0;
   $factor=1.0;
   $subrn="";
   for ($ip=0; $ip<strlen($fromn); $ip++) {
     if (substr($fromn,$ip,1) >= '0' && substr($fromn,$ip,1) <= '9') {
       $subrn.=substr($fromn,$ip,1);
     } else if (substr($fromn,$ip,1) == '+') {
       $subrn.="";
     } else if (substr($fromn,$ip,1) == '-') {
       $subrn.=substr($fromn,$ip,1);
     } else if (substr($fromn,$ip,1) == '.') {
       $subrn.=substr($fromn,$ip,1);
     } else if ($subrn != "") {
       $rn+=($subrn / $factor);
       $factor *= 60.0;
       $subrn="";
     }
   }
   if ($subrn != "") $rn+=($subrn / $factor);
   //echo $fromn . " becomes " . $rn;
   //exit;
   return $rn;
 }
 
 if (isset($_GET['notyet'])) {
 echo '<html><head><title>Australia Waterfalls - RJM Programming - September, 2017</title></head><body><input style="font-size:32px;background-color:yellow;" type=button value="Show Australia Waterfalls now ..." onclick=location.href="./australia_waterfalls.php";></input></body></html>';
 } else { 
 $lhcont=str_replace("</table>", "<table", file_get_contents("https://en.wikipedia.org/wiki/List_of_waterfalls_of_Australia"));
 $url="//www.rjmprogramming.com.au/PHP/Map/map.php";
 $method="POST";
 $iname="my_iframe";
 $ourtitle=urlencode("Australia Waterfalls");
 $ourlabel="[%27Lat%27,";
 $ourvalue="%27Lon%27,%20%27Name%27]";
 $ourdata="";
 $prefix=$url . "?title=" . $ourtitle . "&onclick=y&lines=y&label=" . $ourlabel . "&value=" . $ourvalue . "&data=";
 $isok=true;
 $titleis="";
 $altis="";
 $imgbit="";
 $simgbit="";
 $seimgbit="";
 $tdzdone=0;
 $tdzd=false;
 // Prepare HTML form and iframe for later ...
 $ourform="<" . "form target='" . $iname . "' method='" . $method . "' action='" . $url . "'><input type='hidden' name='wouldlikeyoutoseekpermission' id='wouldlikeyoutoseekpermission' value='y'></input><input name='title' type='hidden' id='title' value='" . $ourtitle . "'></input><input name='onclick' value='y' type='hidden'></input><input name='lines' value='y' type='hidden'></input><input name='label' type='hidden' id='label' value='" . $ourlabel . "'></input><input name='value' type='hidden' id='value' value='" . $ourvalue . "'></input><textarea style='display:none;' rows=40 cols=80 name='data' id='data' value=''></textarea><input style='display:none;' type='submit' id='submit'></input></form>\n";
 $ourscript="<" . "script type='text/javascript'>\nfunction populate() { document.getElementById('title').value=decodeURIComponent('" . $ourtitle . "'); document.getElementById('label').value=decodeURIComponent('" . $ourlabel . "'); document.getElementById('value').value=decodeURIComponent('" . $ourvalue . "'); document.getElementById('data').value=''; \n";
 // Write out start of HTML ready for the one table row that will be created ...
 $tbits=explode('<table', str_replace(' style="text-align:left; font-weight:bold;"','',$lhcont));
 echo '<html><head><script type="text/javascript" src="australian_lighthouses.js" async="async"></script><link href="//www.rjmprogramming.com.au/PHP/emboss_h1.css" rel="stylesheet" type="text/css"><style> body {  background-color: yellow;  } td { border: 2px solid blue; padding-left:10px; padding-right: 10px; background-color: gray; } </style><title>Australia Waterfalls - RJM Programming - September, 2017</title><' . 'script type="text/javascript"> var fsize=' . (-1 + sizeof($tbits)) . ', anim=false, eightthousand=8000, curanim=1;   function startit() { if (anim) { location.href="#td" + curanim; curanim++; if (curanim > fsize || !document.getElementById("td" + curanim)) { curanim=1; }  setTimeout(startit,eightthousand);  }  }  function startorstop() { if (!anim) { anim=true; setTimeout(startit,eightthousand);  } else { anim=false; location.href="#td0"; if (eightthousand > 2999) {  eightthousand-=1000; }   }   }   function after() { document.getElementById("submit").click(); document.getElementById("' .$iname . '").style.display="inline"; } </' . 'script></head><body onload="populate();"><div align="center"><h1>' . selcreate("Australia") . ' Waterfalls ... Thanks to <a target=_blank title="Australia Waterfalls information from Wikipedia ... thanks" href="https://en.wikipedia.org/wiki/List_of_waterfalls_of_Australia">Wikipedia</a></h1></div><table cellspacing=5 style="margin-top:-16px;"><tr>';
 // For each table ...
 for ($i=1; $i<sizeof($tbits); $i++) {
  // For each relevant table cell ...
  $bits=explode('<td><a href="/', $tbits[$i]);
  for ($ii=1; $ii<sizeof($bits); $ii++) {
   $preabits=explode('</td>', $bits[$ii]);
   for ($iij=0; $iij<sizeof($preabits); $iij++) {
    $postabits=explode(">", str_replace("</a>", "", $preabits[$iij]));  
    for ($iijj=1; $iijj<sizeof($postabits); $iijj++) {
     if (strpos($postabits[$iijj], ' src="') !== false || strpos($postabits[$iijj], '<') === false || (strpos($postabits[$iijj], ".") !== false && (strpos($postabits[$iijj], "°S") !== false || strpos($postabits[$iijj], "°N") !== false || strpos($postabits[$iijj], "°E") !== false || strpos($postabits[$iijj], "°W") !== false || strpos($postabits[$iijj], 'itude">') !== false))) {
      // For "still within interesting cells" within table row ...
      if ($isok) {
       // For decimal latitude, longitude content cells ...
       if (strpos($postabits[$iijj], "°") !== false || strpos($postabits[$iijj], 'itude">') !== false) {
        if (strpos($postabits[$iijj], 'itude">') !== false) {
        $xxpostabits=explode('itude">', $postabits[$iijj]);  
        if (strpos($postabits[$iijj], "°") !== false) $xpostabits=explode("°", $postabits[$iijj]);  
        } else {
        $xpostabits=explode("°", $postabits[$iijj]);  
        $xxpostabits=explode("°", $postabits[$iijj]);  
        }
        for ($iijjk=1; $iijjk<sizeof($xxpostabits); $iijjk++) {
         if (strpos((explode("<",$xxpostabits[$iijjk])[0] . "<"),"N<") !== false) {
           $latis="+" . extractnums(explode("<",$xxpostabits[$iijjk])[0]);
         }
         if (strpos((explode("<",$xxpostabits[$iijjk])[0] . "<"),"S<") !== false) {
           $latis="-" . extractnums(explode("<",$xxpostabits[$iijjk])[0]);
         }
         if (strpos((explode("<",$xxpostabits[$iijjk])[0] . "<"),"E<") !== false) {
           $longis="+" . extractnums(explode("<",$xxpostabits[$iijjk])[0]);
         }
         if (strpos((explode("<",$xxpostabits[$iijjk])[0] . "<"),"W<") !== false) {
           $longis="-" . extractnums(explode("<",$xxpostabits[$iijjk])[0]);
         }
         if (substr($xpostabits[$iijjk], 0, 1) == "N") $latis="+" . $xpostabits[$iijjk - 1]; // . "</td>";
         if (substr($xpostabits[$iijjk], 0, 1) == "S") $latis="-" . $xpostabits[$iijjk - 1]; // . "</td>";
         if (substr($xpostabits[$iijjk], 0, 1) == "E") $longis="+" . trim(str_replace("S", "", str_replace("N", "", str_replace("\n", "", $xpostabits[$iijjk - 1])))); // . "</td>";
         if (substr($xpostabits[$iijjk], 0, 1) == "W") $longis="-" . trim(str_replace("S", "", str_replace("N", "", str_replace("\n", "", $xpostabits[$iijjk - 1])))); // . "</td>";
        }
        $altis=trim(str_replace("\n", " ", str_replace("'", "`", $altis)));
        $titleis=trim(str_replace("\n", " ", str_replace("'", "`", $titleis)));
        
        if (substr(($altis . "A"),0,1) < "A") $altis="";
        if (substr(($titleis . "A"),0,1) < "A") $titleis="";
        if ($altis == $titleis) $altis="";
        
        if ($imgbit == "" && 1 == 1) $imgbit="</a>";
        if ($imgbit == "" && 1 == 2) $imgbit=$altis . ", " . $titleis;
        if ($simgbit == "" && 1 == 1) $simgbit="</a>";
        if ($simgbit == "" && 1 == 2) $simgbit=$altis . ", " . $titleis;
        if ($seimgbit == "" && 1 == 1) $seimgbit=urlencode(">" . $altis . ", " . $titleis) . "%3C/a%3E";
        if ($seimgbit == "" && 1 == 2) $seimgbit=">" . $altis . ", " . $titleis . "</a>";
        // Write out cell of information for one dam ...
        
        if (strpos($altis, "ft)") !== false || trim($altis) == "") {
         $altis="";

         if (!$tdzd) {
          if (strpos($listsofar, ";" . $titleis . ";") === false) {
          $listsofar.=$titleis . ";";

         $tdzdone=1;
         $tdzd=true;
         echo "\n<td id=td0 title=Animate><a onclick=startorstop(); style=text-decoration:none;cursor:pointer;>&#127902;</a></td><td id=td" . $tdzdone . "><input title=\"YouTube embedded videos for " . $titleis . " ... thanks\" type=button onclick=\"document.getElementById('my_video').style.display='inline-block'; document.getElementById('my_video').src='//www.rjmprogramming.com.au/HTMLCSS/karaoke_youtube_api.htm?emoji=on&nokaraoke=y&youtubeid=%20%20%20%20%20%20%20%20%20%20%20%20%20%20' + encodeURIComponent('" . $titleis . "');\" value='&#128249;'></input>&nbsp;<input style=\"display:BLOCK;\" title=\"Bonzle Digital Map look for " . $titleis . " ... thanks\" type=button onclick=\"window.open('//www.bonzle.com/c/a?a=ps&s=" . urlencode($titleis) . "','_blank');\" value='&#128506;'></input>&nbsp;<a title='" . $titleis . "' target=_blank href='https://maps.google.com.au/maps?" . "z=15&t=m&q=loc:" . $latis . $longis . "'>" . $titleis . $imgbit . "</td>";
        }
         } else {
          if (strpos($listsofar, ";" . $titleis . ";") === false) {
          $listsofar.=$titleis . ";";

         $tdzdone++;
         echo "\n<td id=td" . $tdzdone . "><input title=\"YouTube embedded videos for " . $titleis . " ... thanks\" type=button onclick=\"document.getElementById('my_video').style.display='inline-block'; document.getElementById('my_video').src='//www.rjmprogramming.com.au/HTMLCSS/karaoke_youtube_api.htm?emoji=on&nokaraoke=y&youtubeid=%20%20%20%20%20%20%20%20%20%20%20%20%20%20' + encodeURIComponent('" . $titleis . "');\" value='&#128249;'></input>&nbsp;<input style=\"display:BLOCK;\" title=\"Bonzle Digital Map look for " . $titleis . " ... thanks\" type=button onclick=\"window.open('//www.bonzle.com/c/a?a=ps&s=" . urlencode($titleis) . "','_blank');\" value='&#128506;'></input>&nbsp;<a title='" . $titleis . "' target=_blank href='https://maps.google.com.au/maps?" . "z=15&t=m&q=loc:" . $latis . $longis . "'>" . $titleis . $imgbit . "</td>";
       }
         }
        } else {
         if (!$tdzd) {
          if (strpos($listsofar, ";" . $altis . ";") === false) {
          $listsofar.=$altis . ";";

         $tdzdone=1;
         $tdzd=true;
         echo "\n<td id=td0 title=Animate><a onclick=startorstop(); style=text-decoration:none;cursor:pointer;>&#127902;</a></td><td id=td" . $tdzdone . "><input title=\"YouTube embedded videos for " . $altis . " ... thanks\" type=button onclick=\"document.getElementById('my_video').style.display='inline-block'; document.getElementById('my_video').src='//www.rjmprogramming.com.au/HTMLCSS/karaoke_youtube_api.htm?emoji=on&nokaraoke=y&youtubeid=%20%20%20%20%20%20%20%20%20%20%20%20%20%20' + encodeURIComponent('" . $altis . "');\" value='&#128249;'></input>&nbsp;<input style=\"display:BLOCK;\" title=\"Bonzle Digital Map look for " . $altis . " ... thanks\" type=button onclick=\"window.open('//www.bonzle.com/c/a?a=ps&s=" . urlencode($altis) . "','_blank');\" value='&#128506;'></input>&nbsp;<a title='" . $altis . ", " . $titleis . "' target=_blank href='https://maps.google.com.au/maps?" . "z=15&t=m&q=loc:" . $latis . $longis . "'>" . $altis . ", " . $titleis . $imgbit . "</td>";
        }
         } else {
          if (strpos($listsofar, ";" . $altis . ";") === false) {
          $listsofar.=$altis . ";";

         $tdzdone++;
         echo "\n<td id=td" . $tdzdone . "><input title=\"YouTube embedded videos for " . $altis . " ... thanks\" type=button onclick=\"document.getElementById('my_video').style.display='inline-block'; document.getElementById('my_video').src='//www.rjmprogramming.com.au/HTMLCSS/karaoke_youtube_api.htm?emoji=on&nokaraoke=y&youtubeid=%20%20%20%20%20%20%20%20%20%20%20%20%20%20' + encodeURIComponent('" . $altis . "');\" value='&#128249;'></input>&nbsp;<input style=\"display:BLOCK;\" title=\"Bonzle Digital Map look for " . $altis . " ... thanks\" type=button onclick=\"window.open('//www.bonzle.com/c/a?a=ps&s=" . urlencode($altis) . "','_blank');\" value='&#128506;'></input>&nbsp;<a title='" . $altis . ", " . $titleis . "' target=_blank href='https://maps.google.com.au/maps?" . "z=15&t=m&q=loc:" . $latis . $longis . "'>" . $altis . ", " . $titleis . $imgbit . "</td>";
        }
         }
        }
        if (1 == 2) $thisdata = ",[" . str_replace("+","",$latis) . "," . str_replace("+","",$longis) . "," . "%22A%20Wikipedia%20image%20(thanks)%20and%20clicking%20link%20for%20Google%20Map%20based%20on%20latitude%20and%20longitude%20of%20%3Ca%20target=_blank%20href=\\\\\"https://maps.google.com.au/maps?" . urlencode("z=15&t=m&q=loc:" . $latis . $longis) . "\\\\\"" . "%3E" . urlencode($altis . ", " . $titleis) . "%3C/a%3E%22,~" . urlencode(str_replace("'","`",str_replace('"','`',$altis . ", " . $titleis))) . "~]";
        //$thisdata = ",[" . str_replace("+","",$latis) . "," . str_replace("+","",$longis) . "," . "%22A%20Wikipedia%20image%20(thanks)%20and%20clicking%20link%20for%20Google%20Map%20based%20on%20latitude%20and%20longitude%20of%20%3Ca%20target=_blank%20href=\\\\\"https://maps.google.com.au/maps?" . urlencode("z=15&t=m&q=loc:" . $latis . $longis) . "\\\\\"" . $seimgbit . "%22,~" . urlencode($altis . ", " . $titleis) . "~]";
        $thisdata = ",[" . str_replace("+","",$latis) . "," . str_replace("+","",$longis) . ",~" . str_replace("+","%20",urlencode(ltrim($altis . " " . $titleis,","))) . "~]";
        // Write out Javascript to populate textarea and rest of form data that will be posted to iframe ...
        $ourscript .= "\n document.getElementById('data').value+=decodeURIComponent('" . $thisdata . "'); ";
        $ourscript .= "\n document.getElementById('data').innerHTML+=decodeURIComponent('" . $thisdata . "'); ";
        $ourdata .= $thisdata;
        $titleis="";
        $altis="";
        $imgbit="";
        $simgbit="";
        $seimgbit="";
       // For image cells ...
       } else if (strpos($postabits[$iijj], "<img ") !== false) {
        $imgbit=str_replace("//", "https://", str_replace("</span", "", str_replace('"', "'", $postabits[$iijj]))) . "></a>";
        
        if (strpos($imgbit, ' src=') !== false) {
          $ibits=explode(' src=', $imgbit);
          $jbits=explode(' ', $ibits[1]);
          $simgbit = " onclick=\" window.open(" . $jbits[0] . ", '" . $altis . "'); \">" . $altis . ", " . $titleis . "</a>";
          $seimgbit = urlencode(" onclick=\\\" window.open(" . $jbits[0] . ", '" . $altis . "','left=200,top=200,width=300,height=300'); \\\">" . $altis . ", " . $titleis . "</a>");
        } else {
          $simgbit="";
          $seimgbit="";
        }
       // For other cells ...
       } else {
        if ($titleis == "") {
          $titleis=str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("</span", "", $postabits[$iijj])));
          $altis=$titleis;
          $altis=str_replace("'", "`", $altis);
          $titleis=str_replace("'", "`", $titleis);
        } else if ($altis == "" || $altis == $titleis) {
          $altis=str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("</span", "", $postabits[$iijj])));
          if ($altis == "") $altis=$titleis;
          $altis=str_replace("'", "`", $altis);
          $titleis=str_replace("'", "`", $titleis);
        }
        if (1 == 2) echo "\n<td>" . str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("</span", "", $postabits[$iijj]))) . "</td>";
	   }
      }
      // Check for end of significant information in this table row ...
      if (strpos($postabits[$iijj], ".") !== false && (strpos($postabits[$iijj], "°S") !== false || strpos($postabits[$iijj], "°N") !== false || strpos($postabits[$iijj], "°E") !== false || strpos($postabits[$iijj], "°W") !== false)) $isok=false;
     }
    }
   }
   // Reset to look for interesting cells in program ...
   $isok=true;
  }
  $titleis="";
  $altis="";
  $imgbit="";
  $simgbit="";
  $seimgbit="";
 }
 // Write out end of HTML including end of row and end of table and form (method=POST with a submit button programmatically clicked via setInterval() at body onload event) and Javascript code and Google Chart Map Chart map.php iframe.
 echo "\n</tr></table>" . $ourform . $ourscript . "\n if (1 == 1) { setTimeout(after, 2000); } \n } \n</" . "script><br><br><div align='center' style='margin-top:-16px;vertical-align:top;'><iframe name='my_video' id='my_video' src='javascript:none' width=63% height=800 style='display:none;'></iframe><iframe name='my_iframe' id='my_iframe' src='javascript:none' width=750 height=500 style='display:none;'></iframe></div></body></html>";
 }
?>
<?php
// australia_ports.php
// RJM Programming
// September, 2017
// Thanks to Wikipedia at https://en.wikipedia.org/wiki/List_of_ports_in_Australia
 ini_set('max_execution_time', 6000);

 $listsofar=";;";

 
 function fixit($useforce, $fwhat) {
   $islat=true;
   if ($useforce || isset($_GET['fixit'])) {
     if (strpos(str_replace("\n","",$fwhat), "<td data-sort-value=") !== false) {
     $trs=explode("</tr>", $fwhat);
     $fwhat="";
     for ($itrs=0; $itrs<sizeof($trs); $itrs++) {
       if (strpos($trs[$itrs], '<td><a href="/') !== false) {
         $prefix=str_replace(explode("<tr>",$trs[$itrs])[-1 + sizeof(explode("<tr>",$trs[$itrs]))],"",$trs[$itrs]);
         $latlongbit=explode('<td><a href="/',explode("<tr>", $trs[$itrs])[-1 + sizeof(explode("<tr>", $trs[$itrs]))])[0];
         $midbit='<td><a href="/' . explode('</td>',explode('<td><a href="/',$trs[$itrs])[-1 + sizeof(explode('<td><a href="/',$trs[$itrs]))])[0] . "</td>";
         //$fwhat.=str_replace($latlongbit,"",$trs[$itrs]) . str_replace("</td>","</span></td>",str_replace('">','"><span class="itude">',$latlongbit)) . "</tr>";
         $fwhat.=$prefix . $midbit . str_replace("</td>","</span></td>",str_replace('">','"><span class="itude">',$latlongbit)) . "</tr>"; 
       } else {
         $fwhat.=$trs[$itrs] . "</tr>";
       }
     }
     //echo str_replace(">","&gt;",str_replace("<","&lt;",$fwhat));
     //exit;
     } else {
     $tds=explode("</td>", $fwhat);
     for ($itds=0; $itds<sizeof($tds); $itds++) {
       $theval=explode(">",$tds[$itds])[-1 + sizeof(explode(">",$tds[$itds]))];
       if (strpos($theval,".") !== false && is_numeric($theval)) {
         if ($islat && $theval >= -90.0 && $theval <= 90.0) {
           if ($theval < 0.0) {
             $fpos=strpos($fwhat, ">" . $theval . "</td>");
             $fpre=substr($fwhat,0,$fpos);
             $fpos+=strlen(">" . $theval . "</td>");
             $frest=substr($fwhat,$fpos);
             $fwhat=$fpre . ">" . floor(str_replace("-","",$theval)) . "° " . (str_replace("-","",$theval) - floor(str_replace("-","",$theval))) * 60.0 / 1.0 . "'" . " S</td>" . $frest;
             $tds=explode("</td>", $fwhat);
             $islat=false;
           } else {
             $fpos=strpos($fwhat, ">" . $theval . "</td>");
             $fpre=substr($fwhat,0,$fpos);
             $fpos+=strlen(">" . $theval . "</td>");
             $frest=substr($fwhat,$fpos);
             //$fwhat=$fpre . "><span>" . str_replace("-","",$theval) . " N</span></td>" . $frest;
             $fwhat=$fpre . ">" . floor(str_replace("-","",$theval)) . "° " . (str_replace("-","",$theval) - floor(str_replace("-","",$theval))) * 60.0 / 1.0 . "'" . " N</td>" . $frest;
             $tds=explode("</td>", $fwhat);
             $islat=false;
           }
         } else if (!$islat && $theval >= -180.0 && $theval <= 180.0) { 
           if ($theval < 0.0) {
             $fpos=strpos($fwhat, ">" . $theval . "</td>");
             $fpre=substr($fwhat,0,$fpos);
             $fpos+=strlen(">" . $theval . "</td>");
             $frest=substr($fwhat,$fpos);
             //$fwhat=$fpre . "><span>" . str_replace("-","",$theval) . " W</span></td>" . $frest;
             $frests=explode("</tr>",$frest);
             $fwhat=$fpre . ">" . floor(str_replace("-","",$theval)) . "° " . (str_replace("-","",$theval) - floor(str_replace("-","",$theval))) * 60.0 / 1.0 . "'" . " W</td>" . str_replace("."," ",$frests[0]) . substr($frest,strlen($frests[0]));
             $tds=explode("</td>", $fwhat);
             $islat=true;
             if ($useforce) return $fwhat;
           } else {
             $fpos=strpos($fwhat, ">" . $theval . "</td>");
             $fpre=substr($fwhat,0,$fpos);
             $fpos+=strlen(">" . $theval . "</td>");
             $frest=substr($fwhat,$fpos);
             //$fwhat=$fpre . "><span>" . str_replace("-","",$theval) . " E</span></td>" . $frest;
             $frests=explode("</tr>",$frest);
             $fwhat=$fpre . ">" . floor(str_replace("-","",$theval)) . "° " . (str_replace("-","",$theval) - floor(str_replace("-","",$theval))) * 60.0 / 1.0 . "'" . " E</td>" . str_replace("."," ",$frests[0]) . substr($frest,strlen($frests[0]));
             $tds=explode("</td>", $fwhat);
             $islat=true;
             if ($useforce) return $fwhat;
           }
         }
       }
     }
     }
   }
   //echo str_replace(">","&gt;",str_replace("<","&lt;",$fwhat));
   //exit;
   return $fwhat;
 }
 
 function extract_nums($fromn) {
   $rn=0.0;
   $factor=1.0;
   $subrn="";
   for ($ip=0; $ip<strlen($fromn); $ip++) {
     if (substr($fromn,$ip,1) >= '0' && substr($fromn,$ip,1) <= '9') {
       $subrn.=substr($fromn,$ip,1);
     } else if (substr($fromn,$ip,1) == '+') {
       $subrn.="";
     } else if (substr($fromn,$ip,1) == '-') {
       $subrn.=substr($fromn,$ip,1);
     } else if (substr($fromn,$ip,1) == '.') {
       $subrn.=substr($fromn,$ip,1);
     } else if ($subrn != "") {
       $rn+=($subrn / $factor);
   //echo $fromn . " to " . $subrn . "/" . $factor . " beComes " . $rn;
   //exit;
       $factor *= 60.0;
       $subrn="";
     }
   }
   if ($subrn != "") $rn+=($subrn / $factor);
   //echo $fromn . " to " . $subrn . "/" . $factor . " beComes " . $rn;
   //exit;
   return $rn;
 }
 
 function selxcreate($def) {
   $ret=$def;
   $selstr='<select onchange=" window.location=this.value; "><option value="' . str_replace(" ", "_", strtolower($def)) . '_ports.php">' . $def . '</option>';
   $cnt=0;
   foreach (glob("*_ports.php") as $filename) {
    if (strpos(($filename . "*"), (str_replace(" ", "_", strtolower($def)) . '_ports.php*')) === false) {
     $cnt++;
     $newidea=str_replace("_", " ", str_replace("_ports.php", "", strtolower($filename)));
     $newideas=explode(" ", $newidea);
     $ideas=strtoupper(substr($newideas[0],0,1)) . strtolower(substr($newideas[0],1));
     for ($ii=1; $ii<sizeof($newideas); $ii++) {
       $ideas.=(" " . strtoupper(substr($newideas[$ii],0,1)) . strtolower(substr($newideas[$ii],1)));
     }
     $selstr.='<option value="' . $filename . '">' . $ideas . '</option>';
    }
   } 
   if ($cnt > 0) return $selstr . "</select>";  
   return $ret;
 }
 
 if (isset($_GET['notyet'])) {
 echo '<html><head><title>Australia Ports - RJM Programming - September, 2017</title></head><body><input style="font-size:32px;background-color:yellow;" type=button value="Show Australia Ports now ..." onclick=location.href="./australia_ports.php";></input></body></html>';
 } else { 
 $lhcont=fixit(false,file_get_contents("https://en.wikipedia.org/wiki/List_of_ports_in_Australia"));
 $url="//www.rjmprogramming.com.au/PHP/Map/map.php";
 $method="POST";
 $iname="my_iframe";
 $ourtitle=urlencode("Australia Ports");
 $ourlabel="[%27Lat%27,";
 $ourvalue="%27Lon%27,%20%27Name%27]";
 $ourdata="";
 $prefix=$url . "?title=" . $ourtitle . "&onclick=y&lines=y&label=" . $ourlabel . "&value=" . $ourvalue . "&data=";
 $isok=true;
 $titleis="";
 $altis="";
 $imgbit="";
 $simgbit="";
 $seimgbit="";
 $tdzdone=0;
 $tdzd=false;
 // Prepare HTML form and iframe for later ...
 $ourform="<" . "form target='" . $iname . "' method='" . $method . "' action='" . $url . "'><input name='title' type='hidden' id='title' value='" . $ourtitle . "'></input><input name='onclick' value='y' type='hidden'></input><input name='lines' value='y' type='hidden'></input><input name='label' type='hidden' id='label' value='" . $ourlabel . "'></input><input type='hidden' name='wouldlikeyoutoseekpermission' id='wouldlikeyoutoseekpermission' value='y'></input><input name='value' type='hidden' id='value' value='" . $ourvalue . "'></input><textarea style='display:none;' rows=40 cols=80 name='data' id='data' value=''></textarea><input style='display:none;' type='submit' id='submit'></input></form>\n";
 $ourscript="<" . "script type='text/javascript'>\nfunction populate() { document.getElementById('title').value=decodeURIComponent('" . $ourtitle . "'); document.getElementById('label').value=decodeURIComponent('" . $ourlabel . "'); document.getElementById('value').value=decodeURIComponent('" . $ourvalue . "'); document.getElementById('data').value=''; \n";
 // Write out start of HTML ready for the one table row that will be created ...
 //$tbits=explode('<tr', str_replace("'E<","'00\" E<",str_replace("'W<","'00\" W<",str_replace("'N<","'00\" N<",str_replace("'S<","'00\" S<",str_replace(' style="text-align:left; font-weight:bold;"','',$lhcont))))));
 $tbits=explode('<tr', str_replace(' style="text-align:left; font-weight:bold;"','',$lhcont));
 echo '<html><head><script type="text/javascript" src="australian_lighthouses.js" async="async"></script><link href="//www.rjmprogramming.com.au/PHP/emboss_h1.css" rel="stylesheet" type="text/css"><style> body {  background-color: pink;  } td { border: 2px solid blue; padding-left:10px; padding-right: 10px; background-color: magenta; } </style><title>Australia Ports - RJM Programming - September, 2017</title><' . 'script type="text/javascript"> var fsize=' . (-1 + sizeof($tbits)) . ', anim=false, eightthousand=8000, curanim=1;   function startit() { if (anim) { location.href="#td" + curanim; curanim++; if (curanim > fsize || !document.getElementById("td" + curanim)) { curanim=1; }  setTimeout(startit,eightthousand);  }  }  function startorstop() { if (!anim) { anim=true; setTimeout(startit,eightthousand);  } else { anim=false; location.href="#td0"; if (eightthousand > 2999) {  eightthousand-=1000; }   }   }  function after() { document.getElementById("submit").click(); document.getElementById("' .$iname . '").style.display="inline"; } </' . 'script></head><body onload="populate();"><div align="center"><h1>' . selxcreate("Australia") . ' Ports ... Thanks to <a target=_blank title="Australia Ports information from Wikipedia ... thanks" href="https://en.wikipedia.org/wiki/List_of_ports_in_Australia">Wikipedia</a></h1></div><table cellspacing=5 style="margin-top:-16px;"><tr>';
 // For each table ...
 //$tbits=explode('<table', $lhcont);
 for ($i=1; $i<sizeof($tbits); $i++) {
  // For each relevant table cell ...
  $bits=explode('<td><a href="/', $tbits[$i]);
    $altis="";
    $titleis="";
  for ($ii=1; $ii<sizeof($bits); $ii++) {
   $preabits=explode('</td>', $bits[$ii]);
   for ($iij=0; $iij<sizeof($preabits); $iij++) {
    $postabits=explode(">", str_replace("</a>", "", $preabits[$iij]));  
    for ($iijj=1; $iijj<sizeof($postabits); $iijj++) {
     //if (strpos($postabits[$iijj], ' src="') !== false || strpos($postabits[$iijj], '<') === false || (strpos($postabits[$iijj], ".") !== false && (strpos($postabits[$iijj], "°S") !== false || strpos($postabits[$iijj], "°N") !== false || strpos($postabits[$iijj], "°E") !== false || strpos($postabits[$iijj], "°W") !== false))) {
      //if ($isok) {
       if (strpos($postabits[$iijj], "°") !== false && 1 == 1) {
       } else if (strpos($postabits[$iijj], "<img ") !== false) {
       } else {
        if ($titleis == "") {
          $titleis=str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("</span", "", $postabits[$iijj])));
          $altis=$titleis;
          $altis=str_replace("'", "`", $altis);
          $titleis=str_replace("'", "`", $titleis);
       //echo str_replace(">", "&gt;", str_replace("<", "&lt;", $titleis . " ... " . $altis));
       //exit;
        } else if ($altis == "" || $altis == $titleis) {
          $altis=str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("</span", "", $postabits[$iijj])));
          if ($altis == "") $altis=$titleis;
          $altis=str_replace("'", "`", $altis);
          $titleis=str_replace("'", "`", $titleis);
       //echo str_replace(">", "&gt;", str_replace("<", "&lt;", $titleis . " .. " . $altis));
       //exit;
        }
        if (1 == 2) echo "\n<td>" . str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("</span", "", $postabits[$iijj]))) . "</td>";
	   }
	  //}
	 //}
    }
    for ($iijj=1; $iijj<sizeof($postabits); $iijj++) {
     if (strpos($postabits[$iijj], ' src="') !== false || strpos($postabits[$iijj], '<') === false || (strpos($postabits[$iijj], ".") !== false && (strpos($postabits[$iijj], "°S") !== false || strpos($postabits[$iijj], "°N") !== false || strpos($postabits[$iijj], "°E") !== false || strpos($postabits[$iijj], "°W") !== false || strpos($postabits[$iijj], "'S</") !== false || strpos($postabits[$iijj], "'N</") !== false || strpos($postabits[$iijj], "'E</") !== false || strpos($postabits[$iijj], "'W</") !== false || strpos($postabits[$iijj], 'itude">') !== false))) {
      // For "still within interesting cells" within table row ...
      if ($isok) {
       // For decimal latitude, longitude content cells ...
       if (strpos($postabits[$iijj], "°") !== false || strpos($postabits[$iijj], 'itude">') !== false) {
        if (strpos($postabits[$iijj], 'itude">') !== false) {
        $xxpostabits=explode('itude">', $postabits[$iijj]);  
        if (strpos($postabits[$iijj], "°") !== false) $xpostabits=explode("°", $postabits[$iijj]);  
        } else {
        $xpostabits=explode("°", $postabits[$iijj]);  
        $xxpostabits=explode("°", $postabits[$iijj]);  
        }
        for ($iijjk=1; $iijjk<sizeof($xxpostabits); $iijjk++) {
         //if (substr($xpostabits[$iijjk], 0, 1) == "N") $latis="+" . $xpostabits[$iijjk - 1]; // . "</td>";
         //if (substr($xpostabits[$iijjk], 0, 1) == "S") $latis="-" . $xpostabits[$iijjk - 1]; // . "</td>";
         //if (substr($xpostabits[$iijjk], 0, 1) == "E") $longis="+" . trim(str_replace("S", "", str_replace("N", "", str_replace("\n", "", $xpostabits[$iijjk - 1])))); // . "</td>";
         //if (substr($xpostabits[$iijjk], 0, 1) == "W") $longis="-" . trim(str_replace("S", "", str_replace("N", "", str_replace("\n", "", $xpostabits[$iijjk - 1])))); // . "</td>";
         if (strpos((explode("<",$xxpostabits[$iijjk])[0] . "<"),"N<") !== false) {
           $latis="+" . extract_nums(explode("<",$xxpostabits[$iijjk])[0]);
         }
         if (strpos((explode("<",$xpostabits[$iijjk])[0] . "<"),"S<") !== false) {
           $latis="-" . extract_nums(explode("<",$xxpostabits[$iijjk])[0]);
         }
         if (strpos((explode("<",$xpostabits[$iijjk])[0] . "<"),"E<") !== false) {
           $longis="+" . extract_nums(explode("<",$xxpostabits[$iijjk])[0]);
         }
         if (strpos((explode("<",$xpostabits[$iijjk])[0] . "<"),"W<") !== false) {
           $longis="-" . extract_nums(explode("<",$xxpostabits[$iijjk])[0]);
         }
         if (strpos($postabits[$iijjk] . " "," S ") !== false) {  // 35°26'49.2"S
           $wls=explode(" ",str_replace('"',"",str_replace("°"," ",str_replace("'"," ",str_replace(" S","",$postabits[$iijjk])))));
           $val=(0.0 - $wls[0]);
           $div=60.0;
           for ($iwls=1; $iwls<sizeof($wls); $iwls++) {
             if (("" . $wls[$iwls]) != "") {
             $wlsiwls=ltrim($wls[$iwls], '0');
             if (("" . $wlsiwls) != "") $val-=($wlsiwls / $div);
             $div*=60;
             }
           }
           $latis="" . $val;
           
         }
         if (strpos($postabits[$iijjk] . " "," N ") !== false) {  // 35°26'49.2"S
           $wls=explode(" ",str_replace('"',"",str_replace("°"," ",str_replace("'"," ",str_replace(" N","",$postabits[$iijjk])))));
           $val=(0.0 + $wls[0]);
           $div=60.0;
           for ($iwls=1; $iwls<sizeof($wls); $iwls++) {
             if (("" . $wls[$iwls]) != "") {
             $wlsiwls=ltrim($wls[$iwls], '0');
             if (("" . $wlsiwls) != "") $val+=($wlsiwls / $div);
             $div*=60;
             }
           }
           $latis="+" . $val;
         }
         if (strpos($tbits[$i]," E</td>") !== false) {  // 35°26'49.2"S
           $postabitsiijjk=explode(">",explode(" E</td>",$tbits[$i])[0])[-1 + sizeof(explode(">",explode(" E</td>",$tbits[$i])[0]))];
           $wls=explode(" ",str_replace('"',"",str_replace("°"," ",str_replace("'"," ",str_replace(" E","",$postabitsiijjk)))));
           $val=(0.0 + $wls[0]);
           $div=60.0;
           $lp=$val;
           for ($iwls=1; $iwls<sizeof($wls); $iwls++) {
             if (("" . $wls[$iwls]) != "") {
             $wlsiwls=ltrim($wls[$iwls], '0');
             if (("" . $wlsiwls) != "") $val+=($wlsiwls / $div);
             $lp.=' ... ' . $postabits[1 + $iijjk] . ' to ' . $wls[$iwls] . ' of ' . $iwls . '(' . $wlsiwls . '/' . $div . ") = " . $val;
             //if (strpos($tbits[$i], "Bermagui") !== false) {
             //  echo $wlsiwls . "/ " . $div . " made value go to " . $val;
             //  exit;
             //}
             $div*=60;
             }
           }
           $longis="+" . $val;
           $lp.=$longis;
         }
         if (strpos($tbits[$i]," W</td>") !== false) {  // 35°26'49.2"S
           $postabitsiijjk=explode(">",explode(" W</td>",$tbits[$i])[0])[-1 + sizeof(explode(">",explode(" W</td>",$tbits[$i])[0]))];
           $wls=explode(" ",str_replace('"',"",str_replace("°"," ",str_replace("'"," ",str_replace(" W","",$postabitsiijjk)))));
           $val=(0.0 - $wls[0]);
           $div=60.0;
           for ($iwls=1; $iwls<sizeof($wls); $iwls++) {
             if (("" . $wls[$iwls]) != "") {
             $wlsiwls=ltrim($wls[$iwls], '0');
             if (("" . $wlsiwls) != "") $val-=($wlsiwls / $div);
             $div*=60;
             }
           }
           $longis="" . $val;
         }
        }
        $altis=trim(str_replace("'", "`", $altis));
        $titleis=trim(str_replace("'", "`", $titleis));
        if (substr(($altis . "A"),0,1) < "A") $altis="";
        if (substr(($titleis . "A"),0,1) < "A") $titleis="";
        if ($altis == $titleis) $altis="";
        if ($imgbit == "" && 1 == 1) $imgbit="</a>";
        if ($imgbit == "" && 1 == 2) $imgbit=$altis . ", " . $titleis;
        if ($simgbit == "" && 1 == 1) $simgbit="</a>";
        if ($simgbit == "" && 1 == 2) $simgbit=$altis . ", " . $titleis;
        if ($seimgbit == "" && 1 == 1) $seimgbit=urlencode(">" . $altis . ", " . $titleis) . "%3C/a%3E";
        if ($seimgbit == "" && 1 == 2) $seimgbit=">" . $altis . ", " . $titleis . "</a>";
        // Write out cell of information for one dam ...
        
        if (trim($altis . $titleis) != "") {
         if (trim($altis) == "") {
          if (!$tdzd) {
          if (strpos($listsofar, ";" . $titleis . ";") === false) {
          $listsofar.=$titleis . ";";

          $tdzdone=1;
          $tdzd=true;
          echo "\n<td id=td0 title=Animate><a onclick=startorstop(); style=text-decoration:none;cursor:pointer;>&#127902;</a></td><td id=td" . $tdzdone . "><input title=\"YouTube embedded videos for " . $titleis . " ... thanks\" type=button onclick=\"document.getElementById('my_video').style.display='inline-block'; document.getElementById('my_video').src='//www.rjmprogramming.com.au/HTMLCSS/karaoke_youtube_api.htm?emoji=on&nokaraoke=y&youtubeid=%20%20%20%20%20%20%20%20%20%20%20%20%20%20' + encodeURIComponent('" . $titleis . "');\" value='&#128249;'></input>&nbsp;<input style=\"font-size:48px;\" title=\"Australia Government website look for " . $titleis . " ... Thanks\" type=button onclick=\"window.open('//www.australia.gov.au/search/site/" . urlencode($titleis) . "?f[0]=sm_field_creator%3Anode%3A207','_blank');\" value='&#127966;'></input>&nbsp;<input style=\"display:BLOCK;\" title=\"Bonzle Digital Map look for " . $titleis . " ... Thanks\" type=button onclick=\"window.open('//www.bonzle.com/c/a?a=ps&s=" . urlencode($titleis) . "','_blank');\" value='&#128506;'></input>&nbsp;<a title='" . $titleis . "' target=_blank href='https://maps.google.com.au/maps?" . "z=15&t=m&q=loc:" . $latis . $longis . "'>" . $titleis . $imgbit . "</td>";
         }
          } else {
          if (strpos($listsofar, ";" . $titleis . ";") === false) {
          $listsofar.=$titleis . ";";

          $tdzdone++;
          echo "\n<td id=td" . $tdzdone . "><input title=\"YouTube embedded videos for " . $titleis . " ... thanks\" type=button onclick=\"document.getElementById('my_video').style.display='inline-block'; document.getElementById('my_video').src='//www.rjmprogramming.com.au/HTMLCSS/karaoke_youtube_api.htm?emoji=on&nokaraoke=y&youtubeid=%20%20%20%20%20%20%20%20%20%20%20%20%20%20' + encodeURIComponent('" . $titleis . "');\" value='&#128249;'></input>&nbsp;<input style=\"font-size:48px;display:BLOCK;\" title=\"Australia Government website look for " . $titleis . " ... Thanks\" type=button onclick=\"window.open('//www.australia.gov.au/search/site/" . urlencode($titleis) . "?f[0]=sm_field_creator%3Anode%3A207','_blank');\" value='&#127966;'></input>&nbsp;<input style=\"display:BLOCK;\" title=\"Bonzle Digital Map look for " . $titleis . " ... Thanks\" type=button onclick=\"window.open('//www.bonzle.com/c/a?a=ps&s=" . urlencode($titleis) . "','_blank');\" value='&#128506;'></input>&nbsp;<a title='" . $titleis . "' target=_blank href='https://maps.google.com.au/maps?" . "z=15&t=m&q=loc:" . $latis . $longis . "'>" . $titleis . $imgbit . "</td>";
          }
          }
             //if (strpos($tbits[$i], "Bermagui") !== false) {
             //   echo $lp . " " . $latis . $longis;
             //   exit;
             //}
        if (1 == 2) $thisdata = ",[" . str_replace("+","",$latis) . "," . str_replace("+","",$longis) . "," . "%22A%20Wikipedia%20image%20(thanks)%20and%20clicking%20link%20for%20Google%20Map%20based%20on%20latitude%20and%20longitude%20of%20%3Ca%20target=_blank%20href=\\\\\"https://maps.google.com.au/maps?" . urlencode("z=15&t=m&q=loc:" . $latis . $longis) . "\\\\\"" . "%3E" . urlencode($titleis) . "%3C/a%3E%22,~" . urlencode(str_replace(' Harbour','',$titleis)) . "~]";
        $thisdata = ",[" . str_replace("+","",$latis) . "," . str_replace("+","",$longis) . "," . "%22A%20Wikipedia%20image%20(thanks)%20and%20clicking%20link%20for%20Google%20Map%20based%20on%20latitude%20and%20longitude%20of%20%3Ca%20target=_blank%20href=\\\\\"https://maps.google.com.au/maps?" . urlencode("z=15&t=m&q=loc:" . $latis . $longis) . "\\\\\"" . $seimgbit . "%22,~" . urlencode(str_replace(' Harbour','',$titleis)) . "~]";
         } else {
          if (!$tdzd) {
          if (strpos($listsofar, ";" . $altis . ";") === false) {
          $listsofar.=$altis . ";";

          $tdzdone=1;
          $tdzd=true;
          echo "\n<td id=td0 title=Animate><a onclick=startorstop(); style=text-decoration:none;cursor:pointer;>&#127902;</a></td><td id=td" . $tdzdone . "><input title=\"YouTube embedded videos for " . $altis . " ... thanks\" type=button onclick=\"document.getElementById('my_video').style.display='inline-block'; document.getElementById('my_video').src='//www.rjmprogramming.com.au/HTMLCSS/karaoke_youtube_api.htm?emoji=on&nokaraoke=y&youtubeid=%20%20%20%20%20%20%20%20%20%20%20%20%20%20' + encodeURIComponent('" . $altis . "');\" value='&#128249;'></input>&nbsp;<input style=\"font-size:48px;display:BLOCK;\" title=\"Australia Government website look for " . $altis . " ... Thanks\" type=button onclick=\"window.open('//www.australia.gov.au/search/site/" . urlencode($altis) . "?f[0]=sm_field_creator%3Anode%3A207','_blank');\" value='&#127966;'></input>&nbsp;<input style=\"display:BLOCK;\" title=\"Bonzle Digital Map look for " . $altis . " ... thanks\" type=button onclick=\"window.open('//www.bonzle.com/c/a?a=ps&s=" . urlencode($altis) . "','_blank');\" value='&#128506;'></input>&nbsp;<a title='" . $altis . "' target=_blank href='https://maps.google.com.au/maps?" . "z=15&t=m&q=loc:" . $latis . $longis . "'>" . $altis . $imgbit . "</td>";
         }
          } else {
          if (strpos($listsofar, ";" . $altis . ";") === false) {
          $listsofar.=$altis . ";";

          $tdzdone++;
          echo "\n<td id=td" . $tdzdone . "><input title=\"YouTube embedded videos for " . $altis . " ... thanks\" type=button onclick=\"document.getElementById('my_video').style.display='inline-block'; document.getElementById('my_video').src='//www.rjmprogramming.com.au/HTMLCSS/karaoke_youtube_api.htm?emoji=on&nokaraoke=y&youtubeid=%20%20%20%20%20%20%20%20%20%20%20%20%20%20' + encodeURIComponent('" . $altis . "');\" value='&#128249;'></input>&nbsp;<input style=\"font-size:48px;display:BLOCK;\" title=\"Australia Government website look for " . $altis . " ... Thanks\" type=button onclick=\"window.open('//www.australia.gov.au/search/site/" . urlencode($altis) . "?f[0]=sm_field_creator%3Anode%3A207','_blank');\" value='&#127966;'></input>&nbsp;<input style=\"display:BLOCK;\" title=\"Bonzle Digital Map look for " . $altis . " ... thanks\" type=button onclick=\"window.open('//www.bonzle.com/c/a?a=ps&s=" . urlencode($altis) . "','_blank');\" value='&#128506;'></input>&nbsp;<a title='" . $altis . "' target=_blank href='https://maps.google.com.au/maps?" . "z=15&t=m&q=loc:" . $latis . $longis . "'>" . $altis . $imgbit . "</td>";
        }
          }
             //if (strpos($tbits[$i], "Bermagui") !== false) {
             //   echo $lp . " " . $latis . $longis;
             //   exit;
             //}
        if (1 == 2) $thisdata = ",[" . str_replace("+","",$latis) . "," . str_replace("+","",$longis) . "," . "%22A%20Wikipedia%20image%20(thanks)%20and%20clicking%20link%20for%20Google%20Map%20based%20on%20latitude%20and%20longitude%20of%20%3Ca%20target=_blank%20href=\\\\\"https://maps.google.com.au/maps?" . urlencode("z=15&t=m&q=loc:" . $latis . $longis) . "\\\\\"" . "%3E" . urlencode($altis) . "%3C/a%3E%22,~" . urlencode(str_replace(' Harbour','',$altis)) . "~]";
        $thisdata = ",[" . str_replace("+","",$latis) . "," . str_replace("+","",$longis) . "," . "%22A%20Wikipedia%20image%20(thanks)%20and%20clicking%20link%20for%20Google%20Map%20based%20on%20latitude%20and%20longitude%20of%20%3Ca%20target=_blank%20href=\\\\\"https://maps.google.com.au/maps?" . urlencode("z=15&t=m&q=loc:" . $latis . $longis) . "\\\\\"" . $seimgbit . "%22,~" . urlencode(str_replace(' Harbour','',$altis)) . "~]";
         }
        }
        // Write out Javascript to populate textarea and rest of form data that will be posted to iframe ...
        $ourscript .= "\n document.getElementById('data').value+=decodeURIComponent('" . $thisdata . "'); ";
        $ourscript .= "\n document.getElementById('data').innerHTML+=decodeURIComponent('" . $thisdata . "'); ";
        $ourdata .= $thisdata;
        //$titleis="";
        //$altis="";
        $imgbit="";
        $simgbit="";
        $seimgbit="";
       // For image cells ...
       } else if (strpos($postabits[$iijj], "<img ") !== false) {
        $imgbit=str_replace("//", "https://", str_replace("</span", "", str_replace('"', "'", $postabits[$iijj]))) . "></a>";
        
        if (strpos($imgbit, ' src=') !== false) {
          $ibits=explode(' src=', $imgbit);
          $jbits=explode(' ', $ibits[1]);
          $simgbit = " onclick=\" window.open(" . $jbits[0] . ", '" . $altis . "'); \">" . $altis . ", " . $titleis . "</a>";
          $seimgbit = urlencode(" onclick=\\\" window.open(" . $jbits[0] . ", '" . $altis . "','left=200,top=200,width=300,height=300'); \\\">" . $altis . ", " . $titleis . "</a>");
        } else {
          $simgbit="";
          $seimgbit="";
        }
       // For other cells ...
       } else if (1 == 2)  {
        if ($titleis == "") {
          $titleis=str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("</span", "", $postabits[$iijj])));
          $altis=$titleis;
          $altis=str_replace("'", "`", $altis);
          $titleis=str_replace("'", "`", $titleis);
        } else if ($altis == "" || $altis == $titleis) {
          $altis=str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("</span", "", $postabits[$iijj])));
          if ($altis == "") $altis=$titleis;
          $altis=str_replace("'", "`", $altis);
          $titleis=str_replace("'", "`", $titleis);
        }
        if (1 == 2) echo "\n<td>" . str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("</span", "", $postabits[$iijj]))) . "</td>";
	   }
      }
      // Check for end of significant information in this table row ...
      if (strpos($postabits[$iijj], ".") !== false && (strpos($postabits[$iijj], "°S") !== false || strpos($postabits[$iijj], "°N") !== false || strpos($postabits[$iijj], "°E") !== false || strpos($postabits[$iijj], "°W") !== false)) $isok=false;
     }
    }
   }
   // Reset to look for interesting cells in program ...
   $isok=true;
  }
  $titleis="";
  $altis="";
  $imgbit="";
  $simgbit="";
  $seimgbit="";
 }
 // Write out end of HTML including end of row and end of table and form (method=POST with a submit button programmatically clicked via setInterval() at body onload event) and Javascript code and Google Chart Map Chart map.php iframe.
 echo "\n</tr></table>" . $ourform . $ourscript . "\n if (1 == 1) { setTimeout(after, 2000); } \n } \n</" . "script><br><br><div align='center' style='margin-top:-16px;vertical-align:top;'><iframe name='my_video' id='my_video' src='javascript:none' width=63% height=800 style='display:none;'></iframe><iframe name='my_iframe' id='my_iframe' src='javascript:none' width=750 height=500 style='display:none;'></iframe></div></body></html>";
 }
?>
