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;
    }
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;
    }
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 ; }
Pretty print the XML
document. Preserve spacing
tab at every newline

@param xml: xml document
Pretty print the XML document . Preserve spacing tab at every newline