1

ブラウザのビュー ソースで 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;

問題は、ブラウザでソースを表示して表示すると、すべてが 1 行に表示されることです。

別の行に表示するにはどうすればよいですか?

テンプレートで \r\n を使用しようとしましたが、うまくいきません。

4

2 に答える 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;

ヒアドキュメントの使用

于 2012-12-01T07:14:05.893 に答える
2

PHP_EOL次のように使用する必要があります。

$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;
于 2012-12-01T07:10:50.280 に答える