doufan1899 2012-08-29 09:51 采纳率: 100%
浏览 300
已采纳

自动缩进HTML代码并显示它

When displaying HTML code in PHP, if I want to indent tags what would be the best way?

For example,

<?php
$html = '<div><p><span>some text</span></p></div>';

echo htmlspecialchars($html);
?>

will give <div><p><span>some text</span</p></div>.

Instead, I'd like to show something like,

<div>
    <p>
        <span>some text</span>
    </p>
</div>
  • 写回答

4条回答 默认 最新

  • dongliyan9190 2012-09-03 07:02
    关注

    You can use htmLawed
    http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/

    this would be your code:

    <?php
      require("htmLawed/htmLawed.php");
      echo "<pre>";
      echo htmlspecialchars(
             htmLawed('<div><p><span>some text</span></p></div>', array('tidy'=>4))
           );
      echo "</pre>";
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退