1

How do I make the html in view source of a browser appear on each line? I'm using php to generate my web pages using a template like this:

$template  = '<!DOCTYPE html>';
$template .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">';
$template .= '<head profile="http://gmpg.org/xfn/11"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
echo $template;

Problem is, it all appears on one line when I view it using view source in a browser.

How do I make it appear on different lines?

I tried using \r\n in the template, but it wont work.

Norman
  • 6,159
  • 23
  • 88
  • 141

2 Answers2

4
$template  = <<<EOT
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type"; content="text/html; charset=UTF-8">
EOT;

echo $template;

Using heredoc

kittycat
  • 14,983
  • 9
  • 55
  • 80
2

You should use PHP_EOL like this:

$template  = '<!DOCTYPE html>' . PHP_EOL;
$template .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">' . PHP_EOL;
$template .= '<head profile="http://gmpg.org/xfn/11"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . PHP_EOL;
echo $template;
Kenny Linsky
  • 1,726
  • 3
  • 17
  • 41