guilmet Posted June 29, 2009 Share Posted June 29, 2009 I am writing a php page, using echo for the html tags, but when I view page source, it's a mess. Is because of echo? is there something else to use instead? Link to comment https://forums.phpfreaks.com/topic/164105-making-page-source-readable-in-php/ Share on other sites More sharing options...
MatthewJ Posted June 29, 2009 Share Posted June 29, 2009 you can do some formatting of the source using \t and \n (tab and new line). <?php echo "<h1><p>This source will all be on one line</p></h1>"; ?> <?php echo "<h1>\n\t<p>This source will all be on multiple lines</p>\n</h1>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/164105-making-page-source-readable-in-php/#findComment-865671 Share on other sites More sharing options...
HPWebSolutions Posted July 4, 2009 Share Posted July 4, 2009 I'd like to recommend not echo'ing the source tags, only echo the values you need in the code. There are a few reasons for this. 1) a good IDE has syntax highlighting for the html code. 2) a good IDE can help you find errors in your HTML code, such as unclosed tags, and can't do this if you are echoing the tags. 3) It is a lot easier for the developer to read the HTML code in the server side source, even without syntax highlighting, when the HTML code is separated from the PHP. 4) It makes it a lot easier to change up the layout of the page later on. If you put a whole bunch of \t and \n formatting tags into your code, it is probably going to become an eyesore to read and debug. For example: <? foreach($array as $key=>$val) { echo '<tr><td>The value of '.$key.' is: </td><td>'.$val.'</td></tr>'; } /* becomes easier to read: */ foreach($array as $key=>$val) { ?> <tr><td>The value of <?php echo $key; ?> is: </td><td><?php echo $val; ?></td></tr>; <? } ?> Link to comment https://forums.phpfreaks.com/topic/164105-making-page-source-readable-in-php/#findComment-868933 Share on other sites More sharing options...
Garethp Posted July 4, 2009 Share Posted July 4, 2009 Your problem is that you aren't using spaces. Try this echo "Some tags "; See how I put the end of the echo on the next line, try it, it'll make your source easier to read Link to comment https://forums.phpfreaks.com/topic/164105-making-page-source-readable-in-php/#findComment-868934 Share on other sites More sharing options...
guilmet Posted July 5, 2009 Author Share Posted July 5, 2009 Thank you HPWebSolutions. I was thinking of that actually, writing the page as an html with php extension, and just use the php inline. Link to comment https://forums.phpfreaks.com/topic/164105-making-page-source-readable-in-php/#findComment-869003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.