• 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

    • Because of the EU (a good thing) newer android devices been getting 5 years worth of security patches. Except some Motorola which found the loop hole, and offer ZERO updates. In addition, Google for years have been making where it can patch some stuff by updating the core Google Play Store itself.  As echoed earlier,  you take the security risk in to your own hand beyond supported.
    • Win11Debloat 06.11.2026 by Razvan Serea Win11Debloat is a lightweight, easy to use PowerShell script that allows you to quickly declutter and customize your Windows experience. It can remove pre-installed bloatware apps, disable telemetry, remove intrusive interface elements and much more. The script also includes many features that system administrators and power users will enjoy. Such as a powerful command-line interface, support for Windows Audit mode and the option to make changes to other Windows users. All changes made by Win11Debloat can be easily reversed, and most removed apps can be restored via the Microsoft Store. A full guide on how to undo the changes is available here. Win11Debloat features: Below is an overview of the key features and functionality offered by Win11Debloat. Please refer to the wiki for more information about the default settings preset. Remove a wide variety of preinstalled apps. Click here for more info. Disable telemetry, diagnostic data, activity history, app-launch tracking & targeted ads. Disable tips, tricks, suggestions & ads across Windows. Disable Windows location services & app location access. Disable Find My Device location tracking. Disable 'Windows Spotlight' and tips & tricks on the lock screen. Disable 'Windows Spotlight' desktop background option. Disable ads, suggestions and the MSN news feed in Microsoft Edge. Hide Microsoft 365 ads on the Settings 'Home' page, or hide the 'Home' page entirely. Disable & remove Microsoft Copilot. Disable Windows Recall. Disable Click to Do, AI text & image analysis tool. Prevent AI service (WSAIFabricSvc) from starting automatically. Disable AI Features in Edge. Disable AI Features in Paint. Disable AI Features in Notepad. Disable the Drag Tray for sharing & moving files. Restore the old Windows 10 style context menu. Turn off Enhance Pointer Precision, also known as mouse acceleration. Disable the Sticky Keys keyboard shortcut. Disable Storage Sense automatic disk cleanup. Disable fast start-up to ensure a full shutdown. ...and more. Once you’ve downloaded the Win11Debloat file (Get.ps1), just follow these quick steps: Locate the Get.ps1 script file. Right-click the file and select Run with PowerShell from the context menu. If prompted by User Account Control (UAC), select Yes to grant the script the necessary administrative permissions. Win11Debloat 06.11.2026 fixes: Fix lock screen spotlight option being disabled when disabling the start recommended section by @Raphire in #619 Fix log message formatting by @Raphire Note The -RemoveCommApps and -RemoveW11Outlook command-line parameters for uninstalling a few specific apps have been removed with this release. If you previously relied on these parameters, please see this wiki page for alternative methods of removing these apps. Download: Win11Debloat 06.11.2026 | Open Source View: Win11Debloat Home Page | Screenshots 1| 2 Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Yes for me, I installed 'old calculator' (Windows 7 calculator) in its place since it is more useful to me. I think paint is the only one I left installed
  • Recent Achievements

    • Rookie
      restore went up a rank
      Rookie
    • Very Popular
      AndrewSteel earned a badge
      Very Popular
    • Veteran
      Taliseian went up a rank
      Veteran
    • One Month Later
      Clizby earned a badge
      One Month Later
    • One Month Later
      Timaximus earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      505
    2. 2
      +Edouard
      162
    3. 3
      PsYcHoKiLLa
      154
    4. 4
      ATLien_0
      83
    5. 5
      Steven P.
      79
  • Tell a friend

    Love Neowin? Tell a friend!