• 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

    • Any Video Converter Free 9.2.3 by Razvan Serea Any Video Converter is an All-in-One video converting tool with an easy-to-use graphical interface, fast converting speed and excellent video quality. Any Video Converter supports all popular video formats and converts your videos to different video formats including MP4, MOV, MKV, M2TS, M4V, MPEG, AVI, WMV, ASF, OGV, WEBM, and more. It supports converting videos to customized percent (50%, 100%, 200%, and more) or resolution (480p, 720p, 1080p, 4K, and more); It supports encoding videos into x264, x265, h263p, xvid, mpeg, wmv, and more. Any Video Converter Free key features: Compatible with Windows 11/10/8.1/8/7 (32-64bit) User interface are available in 14 languages Convert all kinds of video formats including high-definition videos Extract audio from any videos and save as MP3/WMA for your mp3 player Take snapshot from any videos and build your own picture collection Support high-definition for both input and output Batch add videos from hard drive and batch convert Customize output parameters completely as you like Manage your output videos files by group or output profile Merge several video files into a single and long one Clip a video into segments Free Audio Filter: Adjust audio volume and add audio effects Crop frame size to remove black bars and retain what you want only Adjust the brightness, contrast, saturation Rotate or flip or add noise/sharpen effects Produce output video with subtitles of your own dialogue and much, much more... Any Video Converter Free 9.2.3 changelog: Fixed video download engine auto-update failures. Added custom speed control support in the speed change tool. Added support for downloading YouTube AI-generated subtitles. Added support for preserving original audio stream in the format convert tool (e.g., Dolby Atmos, DTS:X). Fixed other bugs and improved overall performance. Download: Any Video Converter Free 9.2.3 | 7.6 MB (Freeware) View: Any Video Converter Free Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Not sure what country you’re in but in many countries you can absolutely jail the sellers behind businesses… in fact I’d say in most countries you can do that
    • I guess we are done since you refuse to read my comment you replied to or my other comment in another thread you were also a part of here.
    • I hate Slack, but Teams is much worse - maybe they've already optimized it, but it was a huge slog the last time I've checked about half a year ago. I miss my Skype.
    • Just ended up switching to Ubuntu. Not sure why I waited.
  • Recent Achievements

    • Dedicated
      jordanspringer earned a badge
      Dedicated
    • Rookie
      Rimplesnort went up a rank
      Rookie
    • One Year In
      Markus94287 earned a badge
      One Year In
    • One Month Later
      Markus94287 earned a badge
      One Month Later
    • Week One Done
      Markus94287 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      510
    2. 2
      +Edouard
      173
    3. 3
      PsYcHoKiLLa
      155
    4. 4
      ATLien_0
      91
    5. 5
      Steven P.
      79
  • Tell a friend

    Love Neowin? Tell a friend!