<?php
  // tags_within.php
  // RJM Programming
  // November, 2014
  //
  // Report on tags within tag

  $fsev = '  document.getElementById("files").addEventListener("change", handleFileSelect, false); ';

  function local_client_files($inmode) {
    global $fsev;
    if ($inmode == "script") {
      return '
      
  var uform;
  var uploadButton; 
  var fileSelect;
  var njk=0
  var resmy="my" + "res";
  var clist="li" + "st";
  var csubmit="sub" + "mit";
  var imgmode=" ";
  var omyh1;
  var fcont="";
  var bigi=0;
  var bigj=0;
  var wl="";
  var doneonce="";
  var presm="sm";
  var bigbuffer="";
  var prevmy_res="";
  var bigf=new Array();
  var urlsuf="";
  var zipcnt="";
  
  function maybedo() {
  }
  
  function lookoutfor() {
  }   
  
  function doonload() {
    setTimeout(maybedo, 1000);
    setInterval(lookoutfor, 5000);
       
    uform = document.getElementById("file-form");
    /' . '/uploadButton = document.getElementById("upload-button");

    
    omyh1 = document.getElementById("myh1");

if (window.File && window.FileReader && window.FileList && window.Blob) {
  var iii=0;
} else {
  document.getElementById("files").style.display = "none";
  /' . '/document.getElementById("file").style.display = "none";
  if (1 == 2) { alert("The File APIs are not fully supported in this browser."); }
}
  
' . $fsev . '  
  
  }
  

  function handleFileSelect(evt) {
    var ourcont="";
    var readers = new Array();
    var f;
    var thelines;
    var thewords;
    var files = evt.target.files; // FileList object

    // files is a FileList of File objects. List some properties.
    var output = [];
    var file; // = files[0];
    var start; // = parseInt(opt_startByte) || 0;
    var stop; // = parseInt(opt_stopByte) || file.size - 1;
    var blob; // = file.slice(start, stop + 1);
    


    omyh1 = document.getElementById("myh1");
    

    
    document.getElementById("list").innerHTML = "";
   
    if (document.body.innerHTML.indexOf("my" + "res") == -1) {
      document.body.innerHTML = document.body.innerHTML + "<span id=my" + "res style=display:none;>~" + "~</span>";
    } else {
      prevmy_res = document.getElementById("my" + "res").innerHTML;
      document.getElementById("my" + "res").innerHTML = "~" + "~";
    }
    

    
    var ourfile;

    for (var iy = 0; iy < files.length; iy++) {
     ourfile = files[iy];
    }  

    var numi;
    
    
    for (var i = 0, f; f = files[i]; i++) {
      bigf[bigf.length] = f.name;
      
     
      document.getElementById("url").value = f.name;
      bigi = eval(1 + i);
      file = f;
      start = 0;
      fcont = "";
      stop = file.size - 1;

      readers[readers.length] = new FileReader();

       imgmode = "n"; /' . '/"y";
     

  
    readers[readers.length - 1].onloadend = function(evt) {
      if (evt.target.readyState == FileReader.DONE) { 
         var xfcont=evt.target.result;
         var thosewordscnt = 0, poff=0, coff=0, thosewords = xfcont.split(String.fromCharCode(32)); 
         var findwordscnt = 0, cfinds, rconts, cfind = "0", huhv, pref="", ihuh, ht; 
         var fws, fwsc="", rcont = " ", bit;
         /' . '/var thoselines = xfcont.split(String.fromCharCode(10)); 
         var ourwords, ourwordcnt = 0; 
         var endtt = document.getElementById("start").value.substring(0,1) + document.getElementById("ctag").value;
         var endd = document.getElementById("start").value.substring(0,1).replace("<",">").replace("[","]").replace("{","}").replace("(",")");
         var ourat = document.getElementById("attrib").value;
         thoselines = xfcont.split(document.getElementById("start").value.substring(0,1) + document.getElementById("ptag").value);
         if (ourat == "") {
         cfind = eval(thoselines.length - 1);
         } else {
         cfind = 0;
         for (var jjjjk=1; jjjjk<thoselines.length; jjjjk++) {
           if (thoselines[jjjjk].substring(0,1) == " " || thoselines[jjjjk].substring(0,1) == endd) {
            if (thoselines.indexOf(ourat) < thoselines.indexOf(endd)) cfind = eval(1 + cfind);
           }
         }
         }
         rconts = xfcont.split(document.getElementById("start").value.substring(0,1) + document.getElementById("ctag").value);
         rcont = eval(rconts.length - 1);
         for (var jjjjm=1; jjjjm<rconts.length; jjjjm++) {
           if (rconts[jjjjm].substring(0,1) != " " && rconts[jjjjm].substring(0,1) != endd) {
            coff = eval(1 + coff);
           }
         }
         for (var jjjj=1; jjjj<thoselines.length; jjjj++) {
           if (thoselines[jjjj].substring(0,1) == " " || thoselines[jjjj].substring(0,1) == endd) {
            ht = thoselines[jjjj].split(endtt + endd);
            thosewordscnt = eval(thosewordscnt + ht.length - 1); 
            ht = thoselines[jjjj].split(endtt + " ");
            thosewordscnt = eval(thosewordscnt + ht.length - 1); 
           } else {
            poff = eval(1 + poff);
           }
         }
         if (document.body.innerHTML.indexOf("~" + "~") == -1) {
          document.body.innerHTML = document.body.innerHTML + "<span id=my" + "res style=display:none;>;" + document.getElementById("url").value + "~" + eval(thoselines.length - 1 - poff) + "~" + thosewordscnt + "~" + cfind + "~" + eval(rcont - coff) + "~" + "~</span>";
         } else {
          document.body.innerHTML = document.body.innerHTML.replace("~" + "~", ";" + document.getElementById("url").value + "~" + eval(thoselines.length - 1 - poff) + "~" + thosewordscnt + "~" + cfind + "~" + eval(rcont - coff) + "~" + "~");
         }
         var sofar = document.getElementById("my" + "res").innerHTML;
         var sofars = sofar.split(";");
         var fwcnt = 0, ht, fto2;
         var sofarlw;
         var ix = eval(sofars.length - 1);
         for (var j=1; j<sofars.length; j++) {
          jj = eval(j * 10);
          if (sofars[j] != "") {
            ix = j - 1;
            sofarlw = sofars[j].split("~");
            document.getElementById("l" + j).innerHTML = sofarlw[1];
            document.getElementById("w" + j).innerHTML = sofarlw[2];
            document.getElementById("f" + j).innerHTML = sofarlw[3];
            document.getElementById("r" + j).innerHTML = sofarlw[4];
            
          }
          document.getElementById("prelist").value = encodeURIComponent(document.getElementById("list").innerHTML);
         }
      }
     
      
    };
    
      output.push("<li id=z" + bigi + ">Filename is <strong id=n" + bigi + ">", escape(f.name), "</strong> ... Type is (", f.type || "n/a", ") ... Date is ",
                  f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : "n/a", " ... Size is ", 
                  f.size, " bytes ... Total (Relevant) Parent/Child tag counts are <span id=l" + bigi + "></span>","(<span id=f" + bigi + "></span>)/", "<span id=r" + bigi + ">", "", "</span> ... Total Child tag count Within Parent Tag is <span id=w" + bigi + ">", "", "</span><span id=f" + bigi + ">", "", "</span><span style=display:none; id=r" + bigi + ">", "", "</span>", 
                  "</li>");

      blob = file.slice(start, stop + 1);
      readers[readers.length - 1].readAsText(blob, "UTF-8");
        


    }
    document.getElementById("list").innerHTML = "<ul>" + output.join("") + "</ul>";
    document.getElementById("prelist").value = encodeURIComponent(document.getElementById("list").innerHTML);
    
    doneonce="y";
    
         
  }

      
';
    } else if ($inmode == "body") {
      return ' onload="doonload();" ' ;
    } else {
      return '&nbsp;&nbsp; ... or ... Local Client Files via <input onmouseover=" if (document.getElementById(clist).innerHTML != ' . "''" . ') {  document.getElementById(csubmit).click();  }   " type="file" multiple="" name="files[]" id="files"><input type="hidden" id="prelist" value=""><div id="list"></div>';
    }
  }

  $url = "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']);
  
  $ptag = ""; //"body";
  $ctag = ""; //"form";
  $attrib = "";
  $start = "<";
  $end = "</";
  $isaspec = "";
  if (isset($_GET['url'])) {
    if (strpos(urldecode($_GET['url']), "http:") !== false || strpos(urldecode($_GET['url']), "https:") !== false || strpos(urldecode($_GET['url']), "HTTP:") !== false || strpos(urldecode($_GET['url']), "HTTPS:") !== false) {
      $url = urldecode($_GET['url']);
    } else if (strpos(urldecode($_GET['url']), "file:") !== false || strpos(urldecode($_GET['url']), "FILE:") !== false || strpos(urldecode($_GET['url']), "File:") !== false) {
      if (strpos(urldecode($_GET['url']), ",") !== false) {
       $url = urldecode($_GET['url']);
       $isfs = explode(",", urldecode($_GET['url']));
       $isaspec = "";
       $mydelim = "";
       for ($ji=0; $ji<sizeof($isfs); $ji++) {
        if ($isfs[$ji] != "") {
         $partisaspec = str_replace("file://", "", str_replace("file:///", "/", urldecode($isfs[$ji])));   // eg. file://c/windows/proxy.pac
         if (substr($partisaspec, 0, 1) != "/" && substr($partisaspec, 1, 1) == "/" && substr($partisaspec, 0, 1) != ".") $partisaspec = substr($partisaspec, 0, 1) . ":" . substr($partisaspec, 1);
         $isaspec .= ($mydelim . $partisaspec);
         $mydelim = ",";
        }
       }
      } else {
       $url = str_replace("file://", "", str_replace("file:///", "/", urldecode($_GET['url'])));   // eg. file://c/windows/proxy.pac
       if (substr($url, 0, 1) != "/" && substr($url, 1, 1) == "/" && substr($url, 0, 1) != ".") $url = substr($url, 0, 1) . ":" . substr($url, 1);
      }
    }
  } else if (isset($_POST['url'])) {
    $url = urldecode($_POST['url']);
    if (strpos(urldecode($_POST['url']), "http:") !== false || strpos(urldecode($_POST['url']), "https:") !== false || strpos(urldecode($_POST['url']), "HTTP:") !== false || strpos(urldecode($_POST['url']), "HTTPS:") !== false) {
      $isaspec = "";
    } else if (strpos(urldecode($_POST['url']), "file:") !== false || strpos(urldecode($_POST['url']), "FILE:") !== false || strpos(urldecode($_POST['url']), "File:") !== false) {
      if (strpos(urldecode($_POST['url']), ",") !== false) {
       $isfs = explode(",", urldecode($_POST['url']));
       $isaspec = "";
       $mydelim = "";
       for ($ji=0; $ji<sizeof($isfs); $ji++) {
        if ($isfs[$ji] != "") {
         $partisaspec = str_replace("file://", "", str_replace("file:///", "/", urldecode($isfs[$ji])));   // eg. file://c/windows/proxy.pac
         if (substr($partisaspec, 0, 1) != "/" && substr($partisaspec, 1, 1) == "/" && substr($partisaspec, 0, 1) != ".") $partisaspec = substr($partisaspec, 0, 1) . ":" . substr($partisaspec, 1);
         $isaspec .= ($mydelim . $partisaspec);
         $mydelim = ",";
        }
       }
      } else if (strpos(urldecode($_POST['url']), "*") !== false || strpos(urldecode($_POST['url']), "%") !== false || strpos(urldecode($_POST['url']), "?") !== false) {
       $isaspec = str_replace("file://", "", str_replace("file:///", "/", urldecode($_POST['url'])));   // eg. file://c/windows/proxy.pac
       if (substr($isaspec, 0, 1) != "/" && substr($isaspec, 1, 1) == "/" && substr($isaspec, 0, 1) != ".") $isaspec = substr($isaspec, 0, 1) . ":" . substr($isaspec, 1);
      }
    } else if (strpos(urldecode($_POST['url']), "*") !== false || strpos(urldecode($_POST['url']), "%") !== false || strpos(urldecode($_POST['url']), "?") !== false) {
      $isaspec = str_replace("file://", "", str_replace("file:///", "/", urldecode($_POST['url'])));   // eg. file://c/windows/proxy.pac
      if (substr($isaspec, 0, 1) != "/" && substr($isaspec, 1, 1) == "/" && substr($isaspec, 0, 1) != ".") $isaspec = substr($isaspec, 0, 1) . ":" . substr($isaspec, 1);
    }
  }
  if (isset($_GET['ptag'])) {
    $ptag = urldecode($_GET['ptag']);
  } else if (isset($_POST['ptag'])) {
    $ptag = urldecode($_POST['ptag']);
  }
  if (isset($_GET['ctag'])) {
    $ctag = urldecode($_GET['ctag']);
  } else if (isset($_POST['ctag'])) {
    $ctag = urldecode($_POST['ctag']);
  }
  if (isset($_GET['attrib'])) {
    $attrib = urldecode($_GET['attrib']);
  } else if (isset($_POST['attrib'])) {
    $attrib = urldecode($_POST['attrib']);
  }
  if (isset($_GET['start'])) {
    $start = urldecode($_GET['start']);
  } else if (isset($_POST['start'])) {
    $start = urldecode($_POST['start']);
  }
  if (isset($_GET['end'])) {
    $end = urldecode($_GET['end']);
  } else if (isset($_POST['end'])) {
    $end = urldecode($_POST['end']);
  }
  
  $makeuplist = ";";
  $suffix = " ... made up of <br>";
  $toosimple = " ... made up of <br>";
  
  if ($url != "" && $ptag != "" && $ctag != "") {
    echo '<!doctype HTML>
<html>
<head>
<script type="text/javascript">

  var which="url";
  var what="/youllneverfindthis/";

' . local_client_files('script') . '
  
  function check(thisfordelim) {
    var outval = thisfordelim.value;
    if (outval.indexOf("http") != 0 && outval.indexOf("HTTP") != 0 && outval.indexOf("file:") != 0 && outval.indexOf("FILE:") != 0 && outval.indexOf("File:") != 0) outval = "http://";
    return outval;
  }


</script>
</head>
<body style=background-color:lightgray;' . local_client_files('body') . '>
';
    echo '<h1 id="myh1" align="center">Find <font color=green>' . str_replace("<", "&lt;", str_replace(">", "&gt;", $ctag)) . '</font> Tags Within <font color=red>' . str_replace("<", "&lt;", str_replace(">", "&gt;", $ptag)) . '</font> Tags With or Without Attributes <font color=orange>' . str_replace("<", "&lt;", str_replace(">", "&gt;", $attrib)) . '</font></h1><br><br>' . "\n";

    echo '<div align="center" style="background-color:yellow;border:15px green solid;"><br><h2>Report regarding ' . $url . ' ...</h2><br><p>' . "\n";
    $cont = "";
    if ($isaspec != "") {   // this is a filespec (list?) rather than one file
      $isspec = explode(",", $isaspec);
      for ($ki=0; $ki<sizeof($isspec); $ki++) {
       if ($isspec[$ki] != "") {
        $jsspec = "";
        if (substr($isspec[$ki],0,3) == "../" && strpos(strtolower($_SERVER['SERVER_NAME']), "rjmprogramming.com.au") !== false) {
          $jsspec = str_replace("/../", "/", (str_replace("*../", str_replace("//", "/", str_replace("/PHP/", "/", str_replace("/PHP//", "/", str_replace("tags_within.php", "", "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']))))), "*" . $isspec[$ki])));
          $isspec[$ki] = str_replace("/../", "/", (str_replace("*../", str_replace("//", "/", str_replace("/PHP/", "/", str_replace("/PHP//", "/", (dirname(__FILE__) . "/")))), "*" . $isspec[$ki])));
        } else if (substr($isspec[$ki],0,2) == "./" && strpos(strtolower($_SERVER['SERVER_NAME']), "rjmprogramming.com.au") !== false) {
          $jsspec = str_replace("/../", "/", (str_replace("*./", str_replace("//", "/", str_replace("/PHjunkP/", "/", str_replace("/PHjunkP//", "/", str_replace("tags_within.php", "", "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']))))), "*" . $isspec[$ki])));
          $isspec[$ki] = str_replace("/../", "/", (str_replace("*./", str_replace("//", "/", str_replace("/PHjunkP/", "/", str_replace("/PHjunkP//", "/", (dirname(__FILE__) . "/")))), "*" . $isspec[$ki])));
        }
        foreach (glob($isspec[$ki]) as $filename) {
         if ($jsspec != "") {
          $filename = str_replace(str_replace("/PHP/", "/", str_replace("/PHP//", "/", (dirname(__FILE__) . "/"))), str_replace("/PHP/tags_within.php", "/", "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI'])), $filename);
          $bitcont = file_get_contents("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . "?url=" . urlencode($filename) . "&start=" . urlencode($start) . "&end=" . urlencode($end) . "&attrib=" . urlencode($attrib) . "&ptag=" . urlencode($ptag) . "&ctag=" . urlencode($ctag));
         } else if (substr($filename, 1, 1) == ":") { // Windows
          $bitcont = file_get_contents("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . "?url=" . urlencode("file://" . substr($filename, 0, 1) . substr($filename, 2)) . "&start=" . urlencode($start) . "&end=" . urlencode($end) . "&attrib=" . urlencode($attrib) . "&ptag=" . urlencode($ptag) . "&ctag=" . urlencode($ctag));
         } else {  // Linux
          $bitcont = file_get_contents("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . "?url=" . urlencode("file://" . $filename) . "&start=" . urlencode($start) . "&end=" . urlencode($end) . "&attrib=" . urlencode($attrib) . "&ptag=" . urlencode($ptag) . "&ctag=" . urlencode($ctag));
         }
         $bits = explode("<h2>", $bitcont);
         if (sizeof($bits) > 1) {
          $thenbits = explode("</div>", $bits[1]);
          echo "<h2>" . $thenbits[0];
         }
		}
	   }
	  }     
    } else {
      $urls = explode(",", $url);  
      if (sizeof($urls) > 1) {   // list of URLs
        $cont = "";
        for ($ki=0; $ki<sizeof($urls); $ki++) {
         if ($urls[$ki] != "") {
          $bitcont = file_get_contents("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . "?url=" . urlencode($urls[$ki]) . "&start=" . urlencode($start) . "&end=" . urlencode($end) . "&attrib=" . urlencode($attrib) . "&ptag=" . urlencode($ptag) . "&ctag=" . urlencode($ctag));
          $bits = explode("<h2>", $bitcont);
          if (sizeof($bits) > 1) {
           $thenbits = explode("</div>", $bits[1]);
           echo "<h2>" . $thenbits[0];
          }
         }
        }
      } else {   // usual, original, one URL
        $cont = file_get_contents($url);
      }
    }
        
    if (strlen($cont) > 0) {
      $cnt = 0;
      $report = "";
      $startchar = substr($start, 0, 1);
      $endchar = str_replace("<", ">", str_replace("[", "]", str_replace("{", "}", str_replace("(", ")", $startchar))));
      if (substr($end, 0, 1) == "/") {
        $pseudo_end = str_replace("/", "|", str_replace($endchar, "@", $end)); 
        $sparecont = str_replace($pseudo_end, $end, str_replace($endchar, " ", str_replace($end, $pseudo_end, $cont)));
        $epll = $end;   // likely is "/>"
        $epul = $end;
        $ecll = $end;
        $ecul = $end;
      } else {
        $sparecont = str_replace($endchar, " ", $cont);
        $epll = $end . strtolower($ptag) . $endchar;  // likely is something like "</body>"
        $epul = $end . strtoupper($ptag) . $endchar;
        $ecll = $end . strtolower($ctag) . $endchar;
        $ecul = $end . strtoupper($ctag) . $endchar;
      }
      $spll = $start . strtolower($ptag) . " "; // likely is something like "<body "
      $spul = $start . strtoupper($ptag) . " ";
      $scll = $start . strtolower($ctag) . " ";
      $scul = $start . strtoupper($ctag) . " ";
      $huhl = strpos($sparecont, $spll);
      $huhu = strpos($sparecont, $spul);
      
      if ($huhl !== false) {
        $huhls = explode($spll, strtolower($sparecont));
        echo "<br>Total parent tag <b><i>" . str_replace("<", "&lt;", str_replace(">", "&gt;", $spll)) . "</b></i> found is <b><i>" . (sizeof($huhls) - 1) . "</b></i><br>";
        if ($attrib != "" && (sizeof($huhls) - 1) >= 1) {
          $rcnt = 0;
          $lcnt = strlen($huhls[0]);
          $newspare = $huhls[0];
          for ($ij=1; $ij<sizeof($huhls); $ij++) {
            $lcnt += strlen($spll);
            if (substr($cont, $lcnt, 1) != $endchar) {
              $wii = explode($endchar, $huhls[$ij]);
              if (strpos(strtolower($attrib), strtolower($wii[0])) !== false) {
                $rcnt = $rcnt + 1;
                $newspare .= $spll;
              } else {
                $newspare .= substr("@!#$%@#$!@#$%%%%%%;", 0, strlen($spll));
                $nextis = strpos($huhls[$ij], $epll);
                if (strlen($epll) > strlen($spll) && $nextis !== false) {
                  $snextis = explode($epll, $huhls[$ij]);
                  $huhls[$ij] = $snextis[0] . substr("@!#$%@#$!@#$%%%%%%;", 0, strlen($epll)) . substr($huhls[$ij], strlen($snextis[0]) + strlen($epll));
                }
              }
            } else {
              $newspare .= substr("@!#$%@#$!@#$%%%%%%;", 0, strlen($spll));
              $nextis = strpos($huhls[$ij], $epll);
              if (strlen($epll) > strlen($spll) && $nextis !== false) {
                  $snextis = explode($epll, $huhls[$ij]);
                  $huhls[$ij] = $snextis[0] . substr("@!#$%@#$!@#$%%%%%%;", 0, strlen($epll)) . substr($huhls[$ij], strlen($snextis[0]) + strlen($epll));
              }
            }
            $lcnt += strlen($huhls[$ij]);
            $newspare .= $huhls[$ij];
          }
          $sparecont = $newspare;
          echo "<br>Total relevant (ie. contains " . $attrib . ") parent tag <b><i>" . str_replace("<", "&lt;", str_replace(">", "&gt;", $spll)) . "</b></i> found is <b><i>" . $rcnt . "</b></i><br>";
          $huhl = strpos(strtolower($sparecont), $spll);
        }
        $huhls = explode($scll, strtolower($sparecont));
        echo "<br>Total child tag <b><i>" . str_replace("<", "&lt;", str_replace(">", "&gt;", $scll)) . "</b></i> found is <b><i>" . (sizeof($huhls) - 1) . "</b></i><br>";
        $found = 0;
        if ($huhl !== false) {
          $huhls = explode($spll, strtolower($sparecont));
          $newspare = "";

          $newspare = $huhls[0];
          for ($ij=1; $ij<sizeof($huhls); $ij++) {
              $newspare .= $spll;
              $nextis = strpos($huhls[$ij], $epll);
              $snextis = explode($epll, $huhls[$ij]);
              $huhls[$ij] = $snextis[0] . substr("@!#$%@#$!@#$%%%%%%;", 0, strlen($epll)) . substr($huhls[$ij], strlen($snextis[0]) + strlen($epll));
              $newspare .= $huhls[$ij];
          }
          $sparecont = $newspare;
          $huhls = explode($spll, strtolower($sparecont));
          if ($huhl !== false) {
             $huhls = explode($spll, strtolower($sparecont));
             for ($ij=1; $ij<sizeof($huhls); $ij++) {
              $nexta = explode($epll, $huhls[$ij]);
              //echo "<br>" . str_replace("<", "&lt;", str_replace(">", "&gt;", $scll)) . " ... " . str_replace("<", "&lt;", str_replace(">", "&gt;", $nexta[0])) . "<br>";
              $stuff = explode($scll, $nexta[0]);
              if (strpos($makeuplist, ";" . (sizeof($stuff) - 1) . ":") !== false) {
                $fi = explode(";" . (sizeof($stuff) - 1) . ":", $makeuplist);
                $fin = explode(";", $fi[1]);
                $makeuplist = str_replace(";" . (sizeof($stuff) - 1) . ":" . $fin[0] . ";", ";" . (sizeof($stuff) - 1) . ":" . ($fin[0] + 1) . ";", $makeuplist);
              } else if (strpos($makeuplist, ":") !== false) {
                $toosimple = "youll_neverfindthis";
                $makeuplist .= (sizeof($stuff) - 1) . ":1;";
              } else { 
                $makeuplist .= (sizeof($stuff) - 1) . ":1;";
              }
              if ($toosimple != $suffix) {
                  $suffix = " ... made up of <br>" . str_replace(":", " count is ", str_replace(";", "<br> ... Groups of ", substr($makeuplist,0,(strlen($makeuplist) - 1))));
              }
              $found += (sizeof($stuff) - 1);
             }       
          }


        }
        echo "<br>Total child tag <b><i>" . str_replace("<", "&lt;", str_replace(">", "&gt;", $scll)) . "</b></i> found within parent tag <b><i>" . str_replace("<", "&lt;", str_replace(">", "&gt;", $spll)) . "</b></i> is <b><i>" . $found . "</b></i>" . str_replace($toosimple, "", $suffix) . "<br>";
      } else if ($huhu !== false) {
        $huhls = explode($spul, strtoupper($sparecont));
        echo "<br>Total parent tag <b><i>" . str_replace("<", "&lt;", str_replace(">", "&gt;", $spll)) . "</b></i> found is <b><i>" . (sizeof($huhls) - 1) . "</b></i><br>";
        if ($attrib != "" && (sizeof($huhls) - 1) >= 1) {
          $rcnt = 0;
          $lcnt = strlen($huhls[0]);
          $newspare = $huhls[0];
          for ($ij=1; $ij<sizeof($huhls); $ij++) {
            $lcnt += strlen($spll);
            if (substr($cont, $lcnt, 1) != $endchar) {
              $wii = explode($endchar, $huhls[$ij]);
              if (strpos(strtolower($attrib), strtolower($wii[0])) !== false) {
                $rcnt = $rcnt + 1;
                $newspare .= $spul;
              } else {
                $newspare .= substr("@!#$%@#$!@#$%%%%%%;", 0, strlen($spul));
                $nextis = strpos($huhls[$ij], $epul);
                if (strlen($epul) > strlen($spul) && $nextis !== false) {
                  $snextis = explode($epul, $huhls[$ij]);
                  $huhls[$ij] = $snextis[0] . substr("@!#$%@#$!@#$%%%%%%;", 0, strlen($epul)) . substr($huhls[$ij], strlen($snextis[0]) + strlen($epul));
                }
              }
            } else {
              $newspare .= substr("@!#$%@#$!@#$%%%%%%;", 0, strlen($spul));
              $nextis = strpos($huhls[$ij], $epul);
              if (strlen($epul) > strlen($spul) && $nextis !== false) {
                  $snextis = explode($epul, $huhls[$ij]);
                  $huhls[$ij] = $snextis[0] . substr("@!#$%@#$!@#$%%%%%%;", 0, strlen($epul)) . substr($huhls[$ij], strlen($snextis[0]) + strlen($epul));
              }
            }
            $lcnt += strlen($huhls[$ij]);
            $newspare .= $huhls[$ij];
          }
          $sparecont = $newspare;
          echo "<br>Total relevant (ie. contains " . $attrib . ") parent tag <b><i>" . str_replace("<", "&lt;", str_replace(">", "&gt;", $spll)) . "</b></i> found is <b><i>" . $rcnt . "</b></i><br>";
          $huhu = strpos(strtoupper($sparecont), $spul);
        }
        $huhls = explode($scul, strtoupper($sparecont));
        echo "<br>Total child tag <b><i>" . str_replace("<", "&lt;", str_replace(">", "&gt;", $scll)) . "</b></i> found is <b><i>" . (sizeof($huhls) - 1) . "</b></i><br>";
        $found = 0;
        if ($huhu !== false) {
          $huhls = explode($spul, strtoupper($sparecont));
          $newspare = "";

          $newspare = $huhls[0];
          for ($ij=1; $ij<sizeof($huhls); $ij++) {
              $newspare .= $spul;
              $nextis = strpos($huhls[$ij], $epul);
              $snextis = explode($epul, $huhls[$ij]);
              $huhls[$ij] = $snextis[0] . substr("@!#$%@#$!@#$%%%%%%;", 0, strlen($epul)) . substr($huhls[$ij], strlen($snextis[0]) + strlen($epul));
              $newspare .= $huhls[$ij];
          }
          $sparecont = $newspare;
          $huhls = explode($spul, strtolower($sparecont));
          if ($huhl !== false) {
             $huhls = explode($spul, strtolower($sparecont));
             for ($ij=1; $ij<sizeof($huhls); $ij++) {
              $nexta = explode($epul, $huhls[$ij]);
              //echo "<br>" . str_replace("<", "&lt;", str_replace(">", "&gt;", $scul)) . " ... " . str_replace("<", "&lt;", str_replace(">", "&gt;", $nexta[0])) . "<br>";
              $stuff = explode($scul, $nexta[0]);
              if (strpos($makeuplist, ";" . (sizeof($stuff) - 1) . ":") !== false) {
                $fi = explode(";" . (sizeof($stuff) - 1) . ":", $makeuplist);
                $fin = explode(";", $fi[1]);
                $makeuplist = str_replace(";" . (sizeof($stuff) - 1) . ":" . $fin[0] . ";", ";" . (sizeof($stuff) - 1) . ":" . ($fin[0] + 1) . ";", $makeuplist);
              } else if (strpos($makeuplist, ":") !== false) {
                $toosimple = "youll_neverfindthis";
                $makeuplist .= (sizeof($stuff) - 1) . ":1;";
              } else { 
                $makeuplist .= (sizeof($stuff) - 1) . ":1;";
              }
              if ($toosimple != $suffix) {
                  $suffix = " ... made up of <br>" . str_replace(":", " count is ", str_replace(";", "<br> ... Groups of ", substr($makeuplist,0,(strlen($makeuplist) - 1))));
              }
              $found += (sizeof($stuff) - 1);
             }       
          }

        }
        echo "<br>Total child tag <b><i>" . str_replace("<", "&lt;", str_replace(">", "&gt;", $scll)) . "</b></i> found within parent tag <b><i>" . str_replace("<", "&lt;", str_replace(">", "&gt;", $spll)) . "</b></i> is <b><i>" . $found . "</b></i>" . str_replace($toosimple, "", $suffix) . "<br>";
      }
    
    }

	echo '</p><hr></div>' . "\n";


    echo '<div align="center" style="background-color:pink;border:5px green solid;"><br><form id="file-form" action="' . "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . '" method="POST">' . "\n";
	echo 'Url: <input onblur=" this.value = check(this); " type="text" name="url" id="url" size=80 value="' . "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . '">' . local_client_files('form') . '<br><br>' . "\n";
	echo 'Parent (in) tag: <input type="text" name="ptag" id="ptag" value="body"><br><br>' . "\n";
	echo 'Child (within) tag: <input type="text" name="ctag" id="ctag" value="form"><br><br>' . "\n";
	echo 'Parent Attribute search (optional): <input type="text" name="attrib" id="attrib" value=""><br><br>' . "\n";
	echo 'Start delimiter: <input type="text" name="start" id="start" value="&lt;"><br><br>' . "\n";
	echo 'End delimiter: <input type="text" name="end" id="end" value="&lt;/"><br><br><br>' . "\n";
	echo '<input type="submit" name="submit" id="submit" value="Report"><br><br>' . "\n";
	echo '</form></div>' . "\n";


  } else {
    echo '<!doctype HTML>
<html>
<head>
<script type="text/javascript">


  var which="url";
  var what="/youllneverfindthis/";

' . local_client_files('script') . '
  
  function check(thisfordelim) {
    var outval = thisfordelim.value;
    if (outval.indexOf("http") != 0 && outval.indexOf("HTTP") != 0 && outval.indexOf("file:") != 0 && outval.indexOf("FILE:") != 0 && outval.indexOf("File:") != 0) outval = "http://";
    return outval;
  }


</script>
</head>
<body style=background-color:lightgray;' . local_client_files('body') . '>
';
    echo '<h1 id="myh1" align="center">Find Tags Within Tags With or Without Attributes</h1><h3 align="center">URL comma separated allowed</h3><br><h3 align="center">Local web server file:// with/without * for filespecs allowed ... eg. file://./*.*ml</h3><br>' . "\n";
    echo '<div align="center" style="background-color:pink;border:9px yellow solid;"><br><form id="file-form" action="' . "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . '" method="POST">' . "\n";
	echo 'Url: <input onblur=" this.value = check(this); " type="text" name="url" id="url" size=80 value="' . "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']) . '">' . local_client_files('form') . '<br><br>' . "\n";
	echo 'Parent (in) tag: <input type="text" name="ptag" id="ptag" value="body"><br><br>' . "\n";
	echo 'Child (within) tag: <input type="text" name="ctag" id="ctag" value="form"><br><br>' . "\n";
	echo 'Parent Attribute search (optional): <input type="text" name="attrib" id="attrib" value=""><br><br>' . "\n";
	echo 'Start delimiter: <input type="text" name="start" id="start" value="&lt;"><br><br>' . "\n";
	echo 'End delimiter: <input type="text" name="end" id="end" value="&lt;/"><br><br><br>' . "\n";
	echo '<input type="submit" name="submit" id="submit" value="Report"><br><br>' . "\n";
	echo '</form></div>' . "\n";
  }

?>
</body>
</html>

