How to get pretty HTML source code from PHP generated output?

空扰寡人 提交于 2020-01-11 10:28:00

问题


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.


回答1:


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.




回答2:


You could use the tidy PECL extension - see this related question for examples.



来源:https://stackoverflow.com/questions/3543859/how-to-get-pretty-html-source-code-from-php-generated-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!