Chciałbym po prostu wiedzieć, czy coś podobnego jest możliwe w php:
<?php
$myhtmlstring = "
?>
<table>
<tr>
<td>test</td>
</tr>
</table>
<?php
";
?>
Powodem tego jest to, że chciałbym móc napisać HTML w tym ładnie wyglądającym formacie, ale po fakcie php przycinałby białą przestrzeń.
Odpowiedzi:
3 dla odpowiedzi № 1Możesz użyć alternatywnej składni heredoc:
$myhtmlstring = <<<EOT
<table>...</table>
EOT;
Lub możesz użyć buforowanie wyjściowe:
<?php
ob_start();
?>
<table>...</table>
<?php
$myhtmlstring = ob_get_clean();
?>
4 dla odpowiedzi nr 2
Możesz użyć heredoc.
3 dla odpowiedzi nr 3
tak
<?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;
?>
1 dla odpowiedzi nr 4
Zwykle używam funkcji bufora, takich jak:
<?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();
?>
Aby uzyskać więcej informacji na temat funkcji bufora, wyszukaj ob_start()
na
php.net.
0 dla odpowiedzi № 5
masz na myśli to?
<?php
$string = "<table border="1">
<tr>
<td> test </td>
</tr>
</table>";
echo $string;
?>