3

How could I use PHP to format HTML code that has had all whitespace stripped?

moinudin
  • 134,091
  • 45
  • 190
  • 216
Rickstar
  • 6,057
  • 21
  • 55
  • 74
  • 7
    In what way has it been compressed? – bdonlan Jan 15 '11 at 12:06
  • Removeing all the spaces and new lines – Rickstar Jan 15 '11 at 12:07
  • 2
    Now if you said that before, this question wouldn't have been closed. And again, I answered an incomplete question. :) –  Jan 15 '11 at 12:08
  • Please feel free to open a new question, as long as you indicate in detail how it's been compressed and what you want it to be decompressed into. Note that removing spaces and newlines isn't really compression - the resulting HTML is still HTML, so if you want some other format you need to be specific about what you want. – bdonlan Jan 15 '11 at 12:09
  • It is compression, you make the file smaller while providing the same output. It's like compressing an MP3: smaller file, same output. Or at least, mostly the same. –  Jan 15 '11 at 12:12
  • 2
    This question is obvious. (At least with its current edit.) It is not ambiguous, vague, incomplete, overly broad, or rhetorical, and can certainly be answered in its current form. There is no reason it should have been closed. A simple edit could have clarified it further. We're here to help people. If you don't want to do that, then move along. – Brad Jan 16 '11 at 19:15
  • I agree with Brad. It was a weak question before the edit, but afterward it is certainly "a real question". – xpda Jan 16 '12 at 19:14
  • IMHO this question is correct and shall not be *closed as not a real question*. However there's question [PHP “pretty print” HTML (not Tidy)](http://stackoverflow.com/questions/768215/php-pretty-print-html-not-tidy), which IMHO provides some answer. – sumid Jan 21 '13 at 21:13

1 Answers1

4

Use HTMLTidy: http://php.net/manual/en/book.tidy.php