问题
I am trying to find a HTML beautifier written in PHP. My sole purpose is to format or tabify few html/php files that are generated by my program. I don't need to check whether it is valid or not.
I tried looking up different libraries like Tidy etc. but I couldn't decide which one to use. Given my purpose is just to format the files on the server, I don't want the overhead of checking for the validity of these files. I need to have support for HTML5 tags and a lot of these libraries do not support them. Hence the only thing I am looking for is to be able to format the files.Something exactly like http://tools.arantius.com/tabifier but for PHP which can be run on the server side.
The files are generated using PHP DomDocument libraries. I tried to use
file_doc->formatOutput = TRUE;
file_doc->preserveWhiteSpace = FALSE;
$this->file_doc->saveHTMLFile($this->filepath);
but it doesn't work.
The files are not generated totally from scratch. Few tags are added when my program is run and the data is sent back to the server where these tags get appended to the file and saved.
回答1:
This question is old but you can use HTML purifier http://htmlpurifier.org/ its has many option, it has one to tidy html code.
来源:https://stackoverflow.com/questions/12790672/html-php-beautifier-formatter-library-written-in-php