dqwh1205 2017-05-01 22:32
浏览 98

当我将缩小的HTML输出到数据库中的文件时,它会对其进行优化

I am creating a few hundred files that are found in a database. $row['content'] is all highly minified html.

I have tried a few solutions to format the html that exist as a string but no solutions have worked too well for formatting minified html on a single line.

I also have rules set on how I format like format using spaces not tabs and 3 spaces per indent.

 $query =  "select page.page_id, page.title, page.content from cms_page page"
if ($result = $mysqli->query($query)) {    
     while($row = $result->fetch_assoc()) {
        file_put_contents($directory. $fileName, $row['content']);
       }
    }
}
  • 写回答

1条回答 默认 最新

  • duanduanxi9441 2017-08-08 20:14
    关注

    You could try out the PHP class Dindent. I have tried it out once, and it seems to do what you are asking. It also has an option for the indentation character(s) you want to use, so your 3 spaces per indent should be possible.

    To use the class with your current code:

    $indenter = new \Gajus\Dindent\Indenter(array('indentation_character'=>'   '));
    $query =  "select page.page_id, page.title, page.content from cms_page page";
    if ($result = $mysqli->query($query)) {    
        while($row = $result->fetch_assoc()) {
            $indented = $indenter->indent($row['content']);
            file_put_contents($directory. $fileName, $indented);
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制