0

How would i go about decompress a html file in php?

The html file is compressed by removing spaces and new lines i cant use the php tidy function as i do not have it insatlled on my server is there any other way of getting around it?

e.g

HTML

<html><title></title><body></body></html>

I need it to look like the following

<html>
<title></title>
<body>
</body>
</html>

Thank you,

Rickstar
  • 6,057
  • 21
  • 55
  • 74
  • If it's just one file, try some online version of tidy, such as: http://infohound.net/tidy/ – miku Jan 15 '11 at 13:17
  • possible duplicate of [Recommended HTML formatter script/utility?](http://stackoverflow.com/questions/143367/recommended-html-formatter-script-utility) – Pekka Jan 15 '11 at 13:17
  • 2
    I'm voting to close as duplicate because there is no "compression" as such in HTML, just the removing of white space, which can be fixed by a HTML formatter. – Pekka Jan 15 '11 at 13:17
  • it's not compressed only tided (for example php tidy), and what you need is to reformat it. Take inspiration here: http://stackoverflow.com/questions/143367/recommended-html-formatter-script-utility – Marek Sebera Jan 15 '11 at 13:18
  • Did the answer to your [previous question](http://stackoverflow.com/questions/4699487/decompress-html-code), despite closed, not help? – Felix Kling Jan 15 '11 at 13:20

2 Answers2

2

http://jsbeautifier.org/

<script>
    var html_source="<html><title></title><body></body></html>";
    var view_html=style_html(html_source, {
          'indent_size': 2,
          'indent_char': ' ',
          'max_char': 78,
          'brace_style': 'expand',
          'unformatted': ['a', 'sub', 'sup', 'b', 'i', 'u']
        });
</script>
Anirudh Ramanathan
  • 46,179
  • 22
  • 132
  • 191
1

If you have a valid xhtml file you can try to use xmllint command with option --format

corsair
  • 658
  • 5
  • 14