watagal Posted May 6, 2008 Share Posted May 6, 2008 Greetings,On HTML pages I generate via PHP, the browser display correctly. But when I view the source, its all on one line - making it difficult to trouble shoot.Is there a way to add a line break (or linefeed)?print '<head>'.linefeed;TIA,Gal Link to comment Share on other sites More sharing options...
Wander Posted May 6, 2008 Share Posted May 6, 2008 you can use \n, only works between dubble quotes "", not between single quotes''for example: echo "Just\nsome\ntext"; will outut: Justsometext if you also wanna use tabs, you can use \t for a tab Link to comment Share on other sites More sharing options...
boen_robot Posted May 6, 2008 Share Posted May 6, 2008 Yes. Infact, there are two ways:1. Add the space "as is" in single quotes, like: print '<head>'; 2. Add "\n" inside a double quoted string, like: print "<head>\n"; To be honest though, I wouldn't add those in PHP. Instead, I'd advise you to use a tool like Firebug to watch the DOM tree (in Firebug, that's the "HTML" tab). Link to comment Share on other sites More sharing options...
zppblood Posted May 6, 2008 Share Posted May 6, 2008 You can also escape out of PHP and write it like a regular HTML file.An Example: <?php if ($_GET['show']=='html') {?><b>Bold Text</b><a href="somefile.php">Some File</a><?php }?> Link to comment Share on other sites More sharing options...
jlhaslip Posted May 7, 2008 Share Posted May 7, 2008 I have a couple of functions I use to control the output of the html source code: // to print $t number of tab charactersfunction tabs($t=1){ for($x = 1; $x <= $t; $x++){ $output .= "\t"; // back-slash t is a tab control character } return $output;}// to print $n number of new-linesfunction nls($n=1){ for($x = 1; $x <= $n; $x++){ $output .= "\n"; // back-slash n is a new-line control character } return $output;} Link to comment Share on other sites More sharing options...
Wander Posted May 7, 2008 Share Posted May 7, 2008 isnt really a good way, first of all it will give an error, because you say $output . = etc, while $output isnt set yet2nd, you can just use the str_repeat function Link to comment Share on other sites More sharing options...
justsomeguy Posted May 12, 2008 Share Posted May 12, 2008 It's best to leave the HTML all on one line. HTML is for the browser, it doesn't matter if people can read it or not. It will also make your pages smaller to leave out the whitespace. If you want to look through the formatted source, you can either browse through it live on the site with a tool like Firebug like boen_robot suggested, or you can copy and paste the generated HTML and use a tool like HTMLTidy to format it. But either of those will be better then having PHP output formatted HTML code. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.