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.

2 Answers 2

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

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;
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.