Jump to content

Formatting HTML

- - - - -

  • Please log in to reply
5 replies to this topic

#1
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
So I realized today, after making a table building class, that it looks ugly when viewing the source. It makes it harder to find specific HTML elements, unless using Firebug or something similar.

I have thought about going in and adding new line characters and tabs so that not all my dynamic HTML is a single line but realizing this makes my PHP code look uglier.

So it seems a flip of either ugly PHP or uglier HTML. It probably wouldn't be a huge deal to format the HTML or even just add new line's every now and then, but I still don't like what it adds to the PHP.

What do you guys prefer doing? Better looking PHP, HTML, or a mix of the two?

Edit: I kept saying PHP. Although this does apply to ASP, Ruby, and other Web languages.

#2
Vladimir

Vladimir

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
What PHP code you have in templates that you can't format nicely? Generally there should be just one-liners:


<ul>

<?php foreach (get_items() as $item): ?>

  <li><a href="<?= url_for('item', $item) ?>"

         target="_blank"><?= $item ?></a></li>

<?php endforeach; ?>

</ul>


I format both HTML and PHP using 2 space as indentation, but I don't use much PHP in templates (generally just conditions and loops).

You can also take a look at Twig - definitely best template engine for PHP.

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Generally, my server side language is more important to me. Ideally, you want to minimize the amount of white-space sent to the browser, anyway. It can make a big difference in speed of the site.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 763 posts
I would choose better look php (or any source code that matters) for better maintenance (debugging, tracing, improving). As for the html, there is a lot of good tools out there. Beside that since it's actually xml, any xml formatting utility will help. For occasional user, every web browsers provide search feature, right?

#5
Grahman

Grahman

    Newbie

  • Members
  • Pip
  • 1 posts
I prefer PHP,to make the web pages on the server have neat code and easy for debugging when problems arise which largely influences the performance of the website.

Edited by Alexander, 10 December 2010 - 09:06 PM.
(removed spam link sig)


#6
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
If you can call webservices in a asynchronous manner, send the html to the service let it format the code and return you the result.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users