• 0

[pic]What beautiful HTML looks like


Question

19 answers to this question

Recommended Posts

  • 0

Code isn't meant to be beautiful. It's the part designers don't want you to see. :laugh:

That's just clean code which will help the developer or anyone who's interested in the makeup of the site to read it easier.

  • 0
Gah, but how do you get the HTML to be tabbed correctly when your generating it in PHP, mine always goes to the ****. :(

I cheat by running it through an XSLT transformation that does pretty printing and such.

Makes it much easier if you start out writing it as proper HTML5 code.

  • 0

I assumed this was going to be a joke

and btw, there is nothing beautiful about that code ;) The php includes for starters are very ugly and potentially messy. And why would you use UTF-8 encoding and still replace every non ascii character with it's html entity. Another one who doesn't know **** about character sets (far too many of those people on this world i'm afraid)

Edited by XerXis
  • 0

HTML5 is already in use in the majority of browsers and sites.

HTML5 is just a standardisation of practises already in use, the parsing algorithm is based on what IE/Safari/Mozilla/Opera did. Old IE only extensions are being promoted to being part of HTML5 if they're useful (and it means the implementations in other browsers are no longer mimicking IE, they're standard)

  • 0
Gah, but how do you get the HTML to be tabbed correctly when your generating it in PHP, mine always goes to the ****. :(

Is there any need for php to generate html tidy? The point of making it tidy is to make it easy to read and edit... but the view source isn't the code you are editing, it should be the php thats tidy, not the outputted html.

I suppose it could potentially help with debugging formatting, but if you get your html clean before you throw php around it will always be right.

  • 0

Beauty is in the eye of the beholder. Somebody may consider this code professional because it is neatly indented. I consider it amateurish because the author is using inline PHP, and in a .HTML document, which would never even parse the code unless he re-configured his server mime type handling, no less.

I seriously urge any budding developers who look at this picture not to take it to heart. Anybody focusing on on their code being "pretty" is most likely doing so because they don't know enough to focus on functionality. In the real world, not only is this a waste of time but it can actually impact your applications negatively.

Just the other day, I noticed my new PHP developer indenting the search result HTML in one of our web applications. In this particular application, an average query yields about 1,000 results, all of which have to be displayed for the client without pagination. Simply removing the indentation my apprentice put in reduced the uncompressed output from the 600KB range to about 250KB.

  • 0
Is there any need for php to generate html tidy? The point of making it tidy is to make it easy to read and edit... but the view source isn't the code you are editing, it should be the php thats tidy, not the outputted html.

I suppose it could potentially help with debugging formatting, but if you get your html clean before you throw php around it will always be right.

Mostly so it looks professional and it also helps with debugging when your PHP generated section isn't off the screen because of tabbing. :p

I wouldn't mind knowing about this XSLT trick as well if its possible.

  • 0

I use output buffering in a shared file to grab the result of the PHP script, then run it through a function that creates an XSLT processor based on a file (http://alex.thefrapp.com/pretty_print.xsl), and then runs the PHP output through it, then I output the result.

The shared file basically detects the user agent and runs one of 2 output functions based on the buffer (if it's HTML, it outputs the HTML5 doctype and changes "/>" into ">", if it's XHTML it runs it through the XSLT file while outputting the proper XML namespaces and PI).

  • 0

Hmm, I did some googling and I came across the Tidy Class, which is built into PHP on windows and an extension on other platforms.

	$out2 = ob_get_contents();

ob_end_clean();
$tidy = new tidy();
$config = array('indent' => TRUE,
				'output-xhtml' => TRUE,
				'wrap' => 200,
				'indent-spaces' => 6);
$tidy->parseString($out2, $config, 'UTF8');
$tidy->cleanRepair();
echo $tidy;

Not sure if it will have any negative affects on a live site, might be worth doing only locally.

  • 0
Beauty is in the eye of the beholder. Somebody may consider this code professional because it is neatly indented. I consider it amateurish because the author is using inline PHP, and in a .HTML document, which would never even parse the code unless he re-configured his server mime type handling, no less.

I seriously urge any budding developers who look at this picture not to take it to heart. Anybody focusing on on their code being "pretty" is most likely doing so because they don't know enough to focus on functionality. In the real world, not only is this a waste of time but it can actually impact your applications negatively.

Regarding "pretty code", it's been my experience that developers who are anal about how their source code is formatted also tend to be anal about the quality of their code.

The few developers that I've worked with who were really inconsistent with their source code formatting were also pretty useless at application design, as if their inability to be consistent with their code formatting pointed to some deeper inability to marshal components together in a logical fashion.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

  • Recent Achievements

    • Week One Done
      davidbazooked earned a badge
      Week One Done
    • One Month Later
      Jamswaz earned a badge
      One Month Later
    • Week One Done
      Jamswaz earned a badge
      Week One Done
    • Rookie
      Marzoid went up a rank
      Rookie
    • Community Regular
      coch went up a rank
      Community Regular
  • Popular Contributors

    1. 1
      +primortal
      514
    2. 2
      PsYcHoKiLLa
      185
    3. 3
      +Edouard
      159
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      75
  • Tell a friend

    Love Neowin? Tell a friend!