Jump to content

line breaks in my HTML code


watagal

Recommended Posts

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...