在PHP变量中定义html代码 [英] Defining html code inside PHP variables

查看:108
本文介绍了在PHP变量中定义html代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PHP变量中包含html代码。
我记得有一种方法可以在php变量中定义html代码,类似于这样的代码:

I want to include html code inside php variables. I remember there was a way to define html code inside a php variable, something similar to this:

<?php $my_var = { ?>
<div>SOME HTML</div>
<?php } ?>

我在 PHP.net 上找到它,但我现在找不到它。
还有别的东西,而不是{>但我不记得确切。
我正在寻找像上面那样直接编写html代码,所以不是这样的: $ my_var ='< div> SOME HTML< / div>';
有什么想法?

I found it on PHP.net but I can't find it now. There was something else instead of the "{" but I don't remember exactly. I am looking to directly write the html code like above, so NOT like this: $my_var = '<div>SOME HTML</div>'; Any ideas?

推荐答案

<?php
$my_var = <<<EOD
<div>SOME HTML</div>
EOD;
?>

它被称为 heredoc 语法。

这篇关于在PHP变量中定义html代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆