Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Formatting HTML


  • Please log in to reply
5 replies to this topic

#1 BlaineSch


    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1559 posts

Posted 06 December 2010 - 11:30 AM

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.
  • 0

#2 Vladimir


    CC Resident

  • Just Joined
  • PipPipPipPip
  • 79 posts

Posted 06 December 2010 - 02:38 PM

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

<?php foreach (get_items() as $item): ?>
  <li><a href="<?= url_for('item', $item) ?>"
         target="_blank"><?= $item ?></a></li>
<?php endforeach; ?>

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.
  • 0

#3 WingedPanther73


    A spammer's worst nightmare

  • Moderator
  • 17757 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

Posted 06 December 2010 - 05:18 PM

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.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/

#4 Luthfi


    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 07 December 2010 - 02:57 AM

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?
  • 0

#5 Grahman


    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 10 December 2010 - 08:00 PM

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)

  • 0

#6 gokuajmes


    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 12 December 2010 - 08:15 PM

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.
  • 0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download