通过PHP进行漂亮的HTML打印而无需验证? [英] Pretty-print HTML via PHP without validation?

查看:62
本文介绍了通过PHP进行漂亮的HTML打印而无需验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动漂亮地打印(大部分是缩进)PHP脚本生成的HTML输出.我一直在与Tidy纠缠,但发现Tidy在验证和清除我的代码的努力中,改变的方式太多了.我知道Tidy的意图很好,但实际上我只是在寻找HTML美化器.是否有一个更简单的库可以在PHP中运行,并且可以漂亮地打印出来?或者,是否可以将Tidy配置为跳过所有验证内容而只是美化?

I'd like to automatically pretty-print (indentation, mostly) the HTML output that my PHP scripts generate. I've been messing with Tidy, but have found that in its efforts to validate and clean my code, Tidy is changing way too much. I know Tidy's intentions are good but I'm really just looking for an HTML beautifier. Is there a simpler library out there that can run in PHP and just do the pretty-printing? Or, is there a way to configure Tidy to skip all the validation stuff and just beautify?

推荐答案

使用Tidy时观察到的行为是DOM API底层使用的结果. DOM API不会处理提供的源代码,而是会重构整个源代码,从而一路进行修复.

The behaviour that you've observed when using Tidy is a result of the underlying use of DOM API. Instead of manipulating the provided source code, DOM API will reconstruct the whole source, thus making fixes along the way.

我写了 Dindent ,它是一个使用Regex的库.除了添加缩进和删除空格外,它没有做任何其他事情.但是,我建议不要出于开发目的而使用此实现.

I've written Dindent, which is a library that uses Regex. It does not do anything beyond adding the indentation and removing whitespaces. However, I advise against using this implementation beyond development purposes.

这篇关于通过PHP进行漂亮的HTML打印而无需验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆