Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2003
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Output buffering & formatting?

    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

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #3
    New Coder
    Join Date
    Jan 2003
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    Code:
    <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

    Code:
    <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>
    Something like that, you know?

  • #4
    New Coder
    Join Date
    Jan 2003
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    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

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    "\t" -->tab

    (double quotes and backslash)

  • #7
    New Coder
    Join Date
    Jan 2003
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #9
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,045
    Thanks
    10
    Thanked 93 Times in 91 Posts
    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 ..
    PEAR::tidy
    http://pecl.php.net/package/tidy
    HTML tidy
    http://tidy.sourceforge.net/
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •