HTML转换为PHP变量(PHP代码之外的HTML) [英] HTML into PHP Variable (HTML outside PHP code)
本文介绍了HTML转换为PHP变量(PHP代码之外的HTML)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是php的新手,想知道我是否可以拥有这样的东西:
I am new to php and wondering if I can have something like this:
<?php
...
magicFunctionStart();
?>
<html>
<head>...</head>
<body>...</body>
</html>
<?php
$variable = magicFunctionEnd();
...
?>
我现在必须使用的是
<?php
...
$variable = "<html><head>...</head><body>...</body></html>"
?>
这很烦人而且不可读.
推荐答案
您是否尝试过输出缓冲"?
Have you tried "output buffering"?
<?php
...
ob_start();
?>
<html>
<head>...</head>
<body>...<?php echo $another_variable ?></body>
</html>
<?php
$variable = ob_get_clean();
...
?>
这篇关于HTML转换为PHP变量(PHP代码之外的HTML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文