私は単純にこれと似たようなことがPHPで可能かどうかを知りたいです:
<?php
$myhtmlstring = "
?>
<table>
<tr>
<td>test</td>
</tr>
</table>
<?php
";
?>
この理由は、この見栄えの良い形式でhtmlを記述できるようにしたいのですが、phpに事後の空白を削除してもらいたいからです。
回答:
回答№1の場合は3別のheredoc構文を使用できます。
$myhtmlstring = <<<EOT
<table>...</table>
EOT;
または、使用することができます 出力バッファリング:
<?php
ob_start();
?>
<table>...</table>
<?php
$myhtmlstring = ob_get_clean();
?>
回答№2については4
あなたは使うことができます ヘドロック.
回答№3の場合は3
はい
<?php
$myhtmlstring = "
<table>
<tr>
<td>test</td>
</tr>
</table>
<?php
";
// Do what you want with the HTML in a PHP variable
// Echo the HTML from the PHP variable to make the webpage
echo $myhtmlstring;
?>
回答№4の場合は1
私は通常、次のようにバッファー関数を使用します。
<?php
$whatever = "Hey man";
// This starts the buffer, so output will no longer be written.
ob_start();
?>
<html>
<head>
<title><?php echo $whatever ?></title>
</head>
<body>
<h1><?php echo $whatever ?></h1>
<p>I like this in part because you can use variables.</p>
</body>
</html>
<?php
// Here"s the magic part!
$myhtmlstring = ob_get_clean();
?>
バッファ関数の詳細については、参照してください ob_start()
に
php.net.
回答№5の場合は0
そういう意味ですか?
<?php
$string = "<table border="1">
<tr>
<td> test </td>
</tr>
</table>";
echo $string;
?>