Ninjakreborn Posted February 8, 2007 Share Posted February 8, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/37606-solved-retaining-source-formatting-during-programming/ Share on other sites More sharing options...
Jenk Posted February 8, 2007 Share Posted February 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/37606-solved-retaining-source-formatting-during-programming/#findComment-179838 Share on other sites More sharing options...
Ninjakreborn Posted February 8, 2007 Author Share Posted February 8, 2007 Perfect, thank you for the advice, I will bookmark this post for later, and try these idea's. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/37606-solved-retaining-source-formatting-during-programming/#findComment-179845 Share on other sites More sharing options...
wildteen88 Posted February 8, 2007 Share Posted February 8, 2007 If you want to format the output add in spaces to indent the outputted code not just \n, example: <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: <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> Quote Link to comment https://forums.phpfreaks.com/topic/37606-solved-retaining-source-formatting-during-programming/#findComment-180055 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.