public static function indent($xml) {
      $cnt = 0;
      $d = 0;
      $t = 0;
      $c = 0;
      while ($cnt != strlen($xml)) {
        $ch = substr($xml, $cnt, 1);
        $ch2 = substr($xml, $cnt, 2);
        $lch = substr($xml, strlen($xml) - 1, 1);
        $f = strlen($xml);
        $a = strlen($xml);

          if ($ch == "<" && $ch2 != "</" && $cnt != "0") {
            $n = "\n";
              for($i = 0; $i <= ($t - $c); $i ++) {
                $n .= "\t";
              }

            $pre = substr($xml, 0, $cnt);
            $af = substr($xml, $cnt, (max(strlen($xml), $cnt) - min(strlen($xml), $cnt)));
            $xml = $pre . $n . $af;

            $a = strlen($xml);
            $d ++;
            $t ++;
          }

          if ($ch2 == "</") {
            $n = "\n";
            for($i = 0; $i <= ($t - $c) - 1; $i ++) {
              $n .= "\t";
            }

            $pre = substr($xml, 0, $cnt);
            $af = substr($xml, $cnt, (max(strlen($xml), $cnt) - min(strlen($xml), $cnt)));
            $xml = $pre . $n . $af;

            $a = strlen($xml);
            $c ++;
          }

          $cnt += ($a - $f) > 0 ? ($a-$f)+1:1;         
      }

      return $xml;
    }