Author Topic: [SOLVED] Retaining source formatting during programming  (Read 209 times)

0 Members and 1 Guest are viewing this topic.

Offline businessman332211Topic starter

  • Fanatic
  • Gender: Male
    • View Profile
    • Information Technologist
[SOLVED] Retaining source formatting during programming
« on: February 08, 2007, 08:36:12 AM »
When you code in Xhtml/css it's easy to mantain the formatting and keep everything need for when you go to view source.  However when I put out a lot of dynamic xhtml here and there, it look's really messed up (as far as indentation on the view source).  Not to say that I don't use /n which help's a lot.  It put's the spacing in the source code, however I have my html formatted, with my php output fomatted left justified, everything work's out like this

<html>
  <head>
    <title>Title Here</title>
  </head>
  <body>
    <form>


    </form>


php out put here.
<ul>
whatever
</ul>


  </body>

</html>

It alway's turned out malformed, hard to read, and not good to lookat.  However that only happen's with my php output, is there a way to retain the indentation, and everything just as if it was straight xhtml?
Business Website: www.infotechnologist.biz
Business #: 206-666-5543

Offline Jenk

  • Devotee
    • View Profile
Re: Retaining source formatting during programming
« Reply #1 on: February 08, 2007, 09:06:14 AM »
You can either:

a) Not care about the specific layout of your markup.

b) Implement a beautifier as a last-stage process (which will add a bit of overhead, but neglible)

c) Use a markup generator, such as the DOM model available in the PHP SPL.

Offline businessman332211Topic starter

  • Fanatic
  • Gender: Male
    • View Profile
    • Information Technologist
Re: Retaining source formatting during programming
« Reply #2 on: February 08, 2007, 09:12:07 AM »
Perfect, thank you for the advice, I will bookmark this post for later, and try these idea's.
Thanks again.
Business Website: www.infotechnologist.biz
Business #: 206-666-5543

Offline wildteen88

  • PHPFreaks Recommended
  • 'Insane!'
  • *
  • Gender: Male
    • View Profile
Re: [SOLVED] Retaining source formatting during programming
« Reply #3 on: February 08, 2007, 01:52:31 PM »
If you want to format the output add in spaces to indent the outputted code not just \n, example:

Code: [Select]
<html>
  <head>
<?php echo "    <title>My Title</title>\n  </head>\n"?>
  <body>

    <p>Select year:
<?php
  
echo "      <select>\n";

  for(
$i 2010$i 2000$i--)
  {
    echo 
"        <option value=\"$i\">$i</option>\n";
  }

  echo 
"      </select>\n";

?>

    </p>

  </body>
</html>

output - lovely formatted code:
Code: [Select]
<html>
  <head>
    <title>My Title</title>
  </head>
  <body>

    <p>Select year:
      <select>
        <option value="2010">2010</option>
        <option value="2009">2009</option>
        <option value="2008">2008</option>
        <option value="2007">2007</option>
        <option value="2006">2006</option>
        <option value="2005">2005</option>
        <option value="2004">2004</option>
        <option value="2003">2003</option>
        <option value="2002">2002</option>
        <option value="2001">2001</option>
      </select>
    </p>

  </body>
</html>

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.