我有这个PHP代码,我希望它能在PHP if语句中运行一些HTMl代码。
if ($_GET['report'] == "success")
{
RUN HTML CODE HERE
} else if ($_GET['report'] == "fail") {
echo 'Error';
}
Html代码:
<li>
<div class="notification success">
<p>Success Notification</p>
<a href="javascript:;" class="close">×</a>
</div>
</li>
答案 0 :(得分:5)
<?php
if ($_GET['report'] == "success") {
?>
<li>
<div class="notification success">
<p>Success Notification</p>
<a href="javascript:;" class="close">×</a>
</div>
</li>
<?php
} elseif ($_GET['report'] == "fail") {
echo 'Error';
}
?>
答案 1 :(得分:3)
您可以关闭您的PHP代码,编写HTML,然后再次打开您的PHP代码。这是一个例子:
<?php
$some_var = "something";
if( true ) {
?>
<div>Some HTML here</div>
<?php } else { ?>
<div>Some other HTML</div>
<?php } ?>
答案 2 :(得分:2)
我认为这更清洁
if ($_GET['report'] == "success")
{
echo file_get_contents("templates/my_html_file.html");
}
else if ($_GET['report'] == "fail")
{
echo 'Error';
}
<强>模板/ my_html_file.html:强>
<li>
<div class="notification success">
<p>Success Notification</p>
<a href="javascript:;" class="close">×</a>
</div>
</li>