Mak*_*Vi. 25 php output-buffering
我是php的新手,想知道我是否可以拥有这样的东西:
<?php
...
magicFunctionStart();
?>
<html>
<head>...</head>
<body>...</body>
</html>
<?php
$variable = magicFunctionEnd();
...
?>
Run Code Online (Sandbox Code Playgroud)
我现在要用的是
<?php
...
$variable = "<html><head>...</head><body>...</body></html>"
?>
Run Code Online (Sandbox Code Playgroud)
这很烦人,不可读.
Wab*_*son 68
你试过"输出缓冲"吗?
<?php
...
ob_start();
?>
<html>
<head>...</head>
<body>...<?php echo $another_variable ?></body>
</html>
<?php
$variable = ob_get_clean();
...
?>
Run Code Online (Sandbox Code Playgroud)
epl*_*ess 15
我想你想要heredoc语法.
例如:
$var = <<<HTML
<html>
<head>
random crap here
</html>
HTML;
Run Code Online (Sandbox Code Playgroud)