如何使浏览器的“查看源”中的html显示在每一行上?我正在使用php生成使用如下模板的web页面:
$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;
问题是,当我在浏览器中使用“视图源”查看它时,它都显示在一行上。
如何使它出现在不同的行上?
我试图在模板中使用\r\n,但它不起作用。
最佳答案
$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;
使用heredoc
http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc