View Full Version : Output buffering & formatting?
12-30-2003, 08:09 PM
I'm making a php site that will have a lot of dirty and cluttered output, with no formatting. I'm looking for something that will buffer the output and format it in a logical pattern, like a WYSIWYG such as Dreamweaver does, adding all the indentations and everything. I don't want to think too hard about it myself heh - too much else to do - so does anyone know of a good one? There's gotta be something out there for this. Thanks
I don't understand the question.
I get that you are dreaming of some magical "garbage in, diamonds out" tool, but that's as far as i get. What do you mean by output? HTML code? What sort of input? Is it structured in any say? What should be the formatting rules?
12-31-2003, 04:40 AM
Well yes, the output is HTML. And these algorithms do exist; Dreamweaver will do such a thing for you, and so will some programming compilers. For example, I could output
<table width="90%" border="0"><tr><td>Hey</td></tr><tr><td>You</td></tr></table><form name="theform"><font size="2"><b>asdf</b></font>
and this function would output
<table width="90%" border="0">
Something like that, you know?
12-31-2003, 04:42 AM
And to further answer your question, I don't care exactly what the formatting rules are, just that it's semi-logical with line breaks and indentations separating different tags and parts of HTML code. I'm not going to request specifics b/c I don't want anyone to spend time actually writing this now. I could write it, but I don't want to spend time on it. I just want to know if anyone's seen one of these functions available for download somewhere.
12-31-2003, 04:54 AM
I doubt that you could find anything. I should imagine that it would be one extremly advanced editor to be able to go through php and sort the html out. Best way is to do it yourself, just add /n for new lines and /t for tabs
I'm sure it can be done. (or has been done) if you have such well formed code where you close all tags etc. It would get messy if you mis a closing tag or if you use stuff like <input ... /> .
But i don't see the point in it. Unless you like to watch your sources in your browser. (That issue has been covered here before)
Anyway, you can include them in your php code like
"\n" --> new line
"\s" --> space
(double quotes and backslash)
12-31-2003, 06:34 AM
Well Nightfire, it wouldn't have to actually sort through PHP code, just regular old HTML output. I figure it would use output buffering to basically caputre everything that PHP prints before actually outputting it. Then it would have that output as a string variable and work through it with regular expressions & string replacement rules and all kinds of junk like that. I just don't really want to do it heh. And I know I can just add the special characters myself, raf, but I was looking for an easier way than doing much of anything myslef. lol. I don't really need this feature, but it has become a little fascination of mine. In my own quirky way, I think it would make the site look 1% more professional. Thanks for the replies so far, though, and I'd still like to hear if anyone's come across this already. It's proven to be a tough thing to search for.
12-31-2003, 05:37 PM
I find it's just easier to watch my output as i'm making the site, the only bit where it trips up is that my design it indented about 8 spaces when it gets to the content, which starts again at offset 0, but i reckon you'd lose too much speed reformatting the output completely to make it viable.
01-01-2004, 07:23 AM
as noted this is something you really do not want to do at runtime... if you `compile` your templates/output then thats different
... if you do want to do it at runtime & if you have decent access to your server setup you could look at PECL::tidy a htmltidy utility ... ther is always the half-chance that your provider has htmlTidy installed , check with them ..
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.