2011-06-01 45 views
1

如何讓我的HTML源代碼的PHP格式化如何讓我的html源代碼格式化

樣品:

<? 
    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); 
?> 

我想是這樣的:

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

我找不到網源,請幫我...

+4

檢查:http://stackoverflow.com/questions/768215/php-pretty-print-html-not-整潔 – Gabriel 2011-06-01 23:12:08

+0

thenks,但不運行,http://www.coderun.com/ide/?w=d35PTnzNW0-Pwk2Fnry6GA – misima 2011-06-01 23:27:08

回答

4

你可以用「 Tidy「。

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

你的例子是這樣的:

<?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); 
?> 
+0

相同的輸出http://www.coderun.com/ide/?w=d35PTnzNW0-Pwk2Fnry6GA我在做什麼錯了我? – misima 2011-06-01 23:48:12

+0

ok run,thenks :) ... – misima 2011-06-01 23:58:03