1

How do I make the html source formatting in php

Sample:

<?
    ob_start();

    $mixed_output = 
    "<div><div>2.</div><div>
          <div>4.</div>
             <div>4.</div>
    </div>  <div>2.</div>
      <div>2.</div>
    </div>";

    echo format_mixed_output($mixed_output);
?>

i want to be this:

<html>
    <div>
      <div>2.</div>
        <div>
          <div>4.</div>
          <div>4.</div>
        </div>
      <div>2.</div>
      <div>2.</div>
    </div>
</html>

i can't find source in net, please help me...

misima
  • 421
  • 5
  • 17

1 Answers1

4

You can use "Tidy".

Example: http://www.php.net/manual/en/tidy.examples.basic.php

Your example would be something like this:

<?php
    $mixed_output = 
"<div><div>2.</div><div>
      <div>4.</div>
         <div>4.</div>
</div>  <div>2.</div>
  <div>2.</div>
</div>";

$config = array(
            'indent'         => true,
            'output-xml'     => true,
            'input-xml'     => true,
            'wrap'         => '1000');

$tidy = new tidy();
$tidy->parseString($mixed_output, $config, 'utf8');
$tidy->cleanRepair();
echo tidy_get_output($tidy);
?>
Wouter van Nifterick
  • 23,603
  • 7
  • 78
  • 122