如何从PHP生成输出获得漂亮的HTML源代码? [英] How to get pretty HTML source code from PHP generated output?

查看:92
本文介绍了如何从PHP生成输出获得漂亮的HTML源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您查看PHP生成的输出的源代码时,通常所有内容都在一行中,这使得前端开发人员很难阅读代码并解决问题。



那么有没有办法让PHP生成的输出结果如下:

 < ul>< li>你好< /立GT;<李> HOLA< /立GT;<李>&的Bonjour LT; /立GT;< / UL> 

 < UL> 
< li> Hello< / li>
< li> Hola< / li>
< li> Bonjour< / li>
< / ul>

无需使用 / n 全部换行服务器端的代码,这只是使这个混乱。

解决方案

为了或多或少干净的PHP生成的代码我使用<$ c $对于 echo 输出字符串,可以使用 \\\
>和 \ t 或其他代码来创建新的行或代码缩进
如果您需要 \来转义它们,这会输出一个,但PHP会把它当作通常的角色来对待。


我知道用这种方式获得漂亮的代码是一件很痛苦的事情,但至少可以让它变得可读。

When you look at the source code of PHP generated output usually everything is on one line, it makes it very hard for front end developers to read the code and trouble shoot.

So is there a way to get PHP generated output to go from this:

<ul><li>Hello</li><li>Hola</li><li>Bonjour</li></ul>

to

<ul>
    <li>Hello</li>
    <li>Hola</li>
    <li>Bonjour</li>
</ul>

WITHOUT using /n line breaks all over the server side code which just makes that messy.

解决方案

For more or less clean looking PHP generated code I used " signs for the echo output Strings, wich enables you to use \n and \t or other codes like that to make new Lines or Code indentation. If you need " signs in your output you need to escape them with \". this will output a " but PHP will treat it like a usual character.

I know it is a pain getting a beautiful code this way but at least it makes it readable.

这篇关于如何从PHP生成输出获得漂亮的HTML源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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