我有问题配售HTML变量,如何将我的HTML内容是这样的:PHP - 上了PHP的标签
<?php
$html =
?>
//in this space, i will place my html
<span></span>
<?php
;
?>
// and i print it
<?php echo $html;?>
我有问题配售HTML变量,如何将我的HTML内容是这样的:PHP - 上了PHP的标签
<?php
$html =
?>
//in this space, i will place my html
<span></span>
<?php
;
?>
// and i print it
<?php echo $html;?>
您需要为此输出缓冲。
<?php
ob_start();
?>
<!-- your html code here -->
<span></span>
<?php
$html = ob_get_clean();
?>
你的答案是正确的! 像我的回答... 起初,但你是先进的! 谢谢... –
据我了解,你可能想看看heredoc语法。但是,你的问题并不完全清楚。
<?php
$html = <<<EOT
<span></span>
<!-- You can place anything in here "without escaping" -->
EOT;
echo $html;
?>
为什么不在PHP标签之间做这件事?
<?php
$html = '<span></span>';
echo $html;
?>
是的,我知道,但跨度是一个html内容,包含许多html标签,每个标签都有字符串,我必须将其转换... 哦,请帮助我! –
你能举一个更详细的例子来说明你想要存储在变量中吗?这会帮助你更轻松地解决这个问题。 – Maritim
哦,谢谢,我已修复它... 请看我的答案在底部! –
您正在寻找输出缓冲,喜欢这里描述:http://stackoverflow.com/questions/4401949/whats-the-use-ob-start-in-php – Adder
你认为阅读文档? http://www.php.net/manual/zh/language.types.string.php – NappingRabbit
hei who is vote down my answer? 我知道如何写清楚变量... 但我有很长的html行,我很困惑... –