整理 PHP 和 HTML 代码?

发布于 2024-09-16 10:14:18 字数 487 浏览 2 评论 0原文

我想知道是否有人可以帮助我,我一直在使用 HTML tidy 和 eclipses 内置函数来整理我的代码。我在以下情况下遇到了很大麻烦...

  1. 当 HTML 通过包含在文件之间拆分时,使用正确的缩进构建结果有助于通过浏览器工具进行调试。

  2. PHP 和 HTML 一起使用时。例如,围绕 HTML 代码的 PHP if 语句,您无法为 PHP 和 HTML 提供正确的缩进。 (自动化此如何正确缩进 PHP/HTML 混合代码?)

我可以忍受的情况一是有办法解决的。但是,如果有人能够针对第二种情况提供解决方案,我将不胜感激。

我使用的工具 eclipse 3.6、Aptanna 2.05 PDT 2.2

I wonder if anyone could please help me I have been using HTML tidy and eclipses built-in function to tidy up my code. I am having great trouble with the following situations...

  1. when HTML is split between files via includes, having result structured with correct indentations helps with debugging via browser tools.

  2. PHP and HTML when used together. for example PHP if statements around HTML code where you wont the correct indentation for both the PHP and HTML. (automating this How to properly indent PHP/HTML mixed code?)

Situation one i can live with and there are ways around it. However, I would be grateful if anyone could offer a solution around situation two.

Tools I use eclipse 3.6, Aptanna 2.05 PDT 2.2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁以何悠 2024-09-23 10:14:18

您可以在 PHP 中使用 HTML Tidy 来清理输出。使用 ob_start() 和朋友将整个 HTML 输出作为字符串获取,然后通过 Tidy 发送。不过,如果您这样做,您可能需要使用某种缓存。

<?php

    function callback($buffer)
    {
        // Clean up

        $config = array(
            'indent'         => true,
            'output-xhtml'   => true,
            'wrap'           => 200);

        return tidy_repair_string($buffer, $config, 'utf8');
    }


    // Do some output.

    ob_start("callback");
    ?>
        <html>
            <body>
                <p>Outputting stuff here</p>
                <p>
                    Testing a broken tag:
                    <span> This span should be closed by Tidy.
                </p>
            </body>
        </html>
    <?php
    ob_end_flush();

?>

You could use HTML Tidy from within PHP to clean up your output. Use ob_start() and friends to get the whole HTML output as a string, then send it through Tidy. You might want to use som sort of caching if you do this, though.

<?php

    function callback($buffer)
    {
        // Clean up

        $config = array(
            'indent'         => true,
            'output-xhtml'   => true,
            'wrap'           => 200);

        return tidy_repair_string($buffer, $config, 'utf8');
    }


    // Do some output.

    ob_start("callback");
    ?>
        <html>
            <body>
                <p>Outputting stuff here</p>
                <p>
                    Testing a broken tag:
                    <span> This span should be closed by Tidy.
                </p>
            </body>
        </html>
    <?php
    ob_end_flush();

?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文